﻿--Migration
IF SCHEMA_ID('kreta') IS NULL
    EXEC('CREATE SCHEMA kreta');
GO

DROP PROCEDURE IF EXISTS kreta.uspSetSession;
GO

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

SELECT @IntezmenyId = ID
FROM T_INTEZMENY
WHERE C_AZONOSITO = REPLACE(REPLACE(USER_NAME(), 'KR_', ''), '_user', '');

SELECT @TanevId = ID
FROM T_TANEV
WHERE C_INTEZMENYID = @IntezmenyId
AND C_AKTIV = 'T';

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

GRANT EXECUTE ON SCHEMA::kreta TO PUBLIC;
GO

