tags:

views:

27

answers:

1

Hello,

is there any way to make a certain session execute all commands as a certain user? I cannot use the execute as clause because it mustn't be hardcoded.

I need something along the lines of this pseudocode:

ALTER SESSION sessionid SET EXECUTING_USER=someuser

A: 

EXECUTE AS can accept variables (in 2008 at least) so you don't have to hardcode the name to use it.

DECLARE @username sysname = 'foobar'

EXECUTE AS USER = @username

SELECT SESSION_USER

Journey
But how can I set it for the whole session? Every call in the session should be executed as the specified user!
Falcon