﻿ 
                DROP TABLE IF EXISTS tmpForSwitchDictionaryItemBase 
                CREATE TABLE tmpForSwitchDictionaryItemBase(RegiID int, UjID int, TanevID int, C_NAME nvarchar(500), C_TYPE nvarchar(64))
                DECLARE @TEMP_EnvironmentName nvarchar(1000)  
                SET @TEMP_EnvironmentName = (SELECT TOP 1 [Value] FROM dev.EnvironmentInfo WHERE [Key] = 'Kornyezet')
                 IF @TEMP_EnvironmentName = 'KK' BEGIN -----  7794 ----- tanszakvezető -----
                INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
                SELECT DIB.ID, 7794, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE 
                FROM T_DICTIONARYITEMBASE DIB INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2019/2020'
                WHERE DIB.C_TYPE = N'VezetoiOraszamokTipus' AND DIB.C_NAME = N'tanszakvezető' AND DIB.TOROLT = 'F' 
                UPDATE DIB SET 
                DIB.TOROLT = 'T' 
                FROM T_DICTIONARYITEMBASE DIB INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2019/2020' 
                WHERE DIB.C_TYPE = N'VezetoiOraszamokTipus' AND DIB.C_NAME = N'tanszakvezető' AND DIB.TOROLT = 'F' 
                 END 
                 IF @TEMP_EnvironmentName = 'NSZFH' BEGIN -----  7794 ----- tanszakvezető -----
                INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
                SELECT DIB.ID, 7794, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE 
                FROM T_DICTIONARYITEMBASE DIB INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2019/2020'
                WHERE DIB.C_TYPE = N'VezetoiOraszamokTipus' AND DIB.C_NAME = N'tanszakvezető' AND DIB.TOROLT = 'F' 
                UPDATE DIB SET 
                DIB.TOROLT = 'T' 
                FROM T_DICTIONARYITEMBASE DIB INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2019/2020' 
                WHERE DIB.C_TYPE = N'VezetoiOraszamokTipus' AND DIB.C_NAME = N'tanszakvezető' AND DIB.TOROLT = 'F' 
                 END 
                 IF @TEMP_EnvironmentName = 'HOI' BEGIN -----  7794 ----- tanszakvezető -----
                INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
                SELECT DIB.ID, 7794, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE 
                FROM T_DICTIONARYITEMBASE DIB INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2019/2020'
                WHERE DIB.C_TYPE = N'VezetoiOraszamokTipus' AND DIB.C_NAME = N'tanszakvezető' AND DIB.TOROLT = 'F' 
                UPDATE DIB SET 
                DIB.TOROLT = 'T' 
                FROM T_DICTIONARYITEMBASE DIB INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2019/2020' 
                WHERE DIB.C_TYPE = N'VezetoiOraszamokTipus' AND DIB.C_NAME = N'tanszakvezető' AND DIB.TOROLT = 'F' 
                 END 
                 IF @TEMP_EnvironmentName = 'AZURE' BEGIN -----  7794 ----- tanszakvezető -----
                INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
                SELECT DIB.ID, 7794, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE 
                FROM T_DICTIONARYITEMBASE DIB INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2019/2020'
                WHERE DIB.C_TYPE = N'VezetoiOraszamokTipus' AND DIB.C_NAME = N'tanszakvezető' AND DIB.TOROLT = 'F' 
                UPDATE DIB SET 
                DIB.TOROLT = 'T' 
                FROM T_DICTIONARYITEMBASE DIB INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2019/2020' 
                WHERE DIB.C_TYPE = N'VezetoiOraszamokTipus' AND DIB.C_NAME = N'tanszakvezető' AND DIB.TOROLT = 'F' 
                 END 
                 
                EXEC [dev].uspSwitchDictionaryItemBaseFromTmp 