is there any way to make a certain session execute all commands as a开发者_StackOverflow社区 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
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
精彩评论