
DROP PROCEDURE IF EXISTS kreta.uspSetSession;
GO

CREATE PROCEDURE kreta.uspSetSession
WITH EXECUTE AS OWNER
AS
SET NOCOUNT ON;
DECLARE @IntezmenyId INT;
DECLARE @TanevId INT;

SELECT @IntezmenyId = ID
FROM T_INTEZMENY
WHERE C_AZONOSITO = REPLACE(REPLACE(ORIGINAL_LOGIN(), 'KR_', ''), '_user', '')
AND TOROLT = 'F'; -- index seek

SELECT @TanevId = ID
FROM T_TANEV
WHERE C_INTEZMENYID = @IntezmenyId
AND C_AKTIV = 'T'
AND TOROLT = 'F'; -- index seek

EXEC sp_set_session_context N'INTEZMENYID', @IntezmenyId;
EXEC sp_set_session_context N'TANEVID', @TanevId;
GO
