DECLARE @Ctx varbinary(128)
DECLARE @username varchar(30)
SET @Username='ibica'
SELECT @Ctx = CONVERT(varbinary(128), @Username)
SET CONTEXT_INFO @Ctx
SET @username = CONVERT(VarChar(128), CONTEXT_INFO());
PRINT @username
DECLARE @ID_User int
SET @ID_User = ( SELECT Users.ID_User
FROM Users
WHERE Users.Username=@username )
PRINT @ID_User
I'm setting the context_info correctly, because PRINT @username returns the right value, but I get an empty line on the second print. If i put a value instead of @username in the where clause above, it also prints the right value. What am I missing?
DECLARE @username varchar(30)
SET @username = 'ibica';
PRINT @username
DECLARE @ID_User int
SET @ID_User = ( SELECT Users.ID_User
FROM Users
WHERE Users.Username=@username )
PRINT 'smth'
PRINT @ID_User PRINT 'smth'
I removed the CONTEXT_INFO and now my output is correct. So it has to have something to do with CONTEXT_INFO.