Incorrect syntax: EXECUTE AS User = dbo.fnc_GetUser()

Hi all,

We have a stored procedure containing following code: EXECUTE AS User = dbo.fnc_GetUser(). Studio does not correctly recognize it and gives us warning of "TSD2010: Incorrect syntax near dbo.". Any idea how to correct this?

Thanks, Pavel

[277 byte] By [PavelKaufman] at [2008-1-7]
# 1

This is a problem in our T-SQL parser, the grammar does not recognize this is valid syntax. I was not even aware this was allowed syntax and the SQL Books Online is not either. Not that this is an excuse, apparently it works and is not documented as such, since the documentation suggests literal input only.

We will get this fixed for the Orcas release of VSDBPro.

-GertD

http://blogs.msdn.com/gertd

GertDrapers-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Database Professionals...
# 2

A workaround is to indirect via a variable.

Code Snippet

CREATE PROCEDURE [dbo].[Procedure1]

AS

BEGIN

SET NOCOUNT ON

DECLARE @u sysname

SET @u = dbo.fn_getuser();

EXECUTE AS USER = @u

SELECT SUSER_NAME(), USER_NAME();

REVERT

SELECT SUSER_NAME(), USER_NAME();

RETURN 0

END;

-GertD

http://blogs.msdn.com/gertd

GertDrapers-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Database Professionals...

Visual Studio Team System

Site Classified