﻿
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 
  INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
  SELECT DIB.ID, 7883, 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'EvfolyamTipus' AND DIB.C_NAME = N'1/13 5-ös szintű technikum' 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'EvfolyamTipus' AND DIB.C_NAME = N'1/13 5-ös szintű technikum' AND DIB.TOROLT = 'F' 
  UPDATE DIB SET DIB.TOROLT = 'F'     ,DIB.C_NAME = N'1/13 5-ös szintű technikum' 
    ,DIB.C_NAME_1 = N'1/13 5-ös szintű technikum' 
    ,DIB.C_NAME_4 = N'13' 
    ,DIB.C_TYPE = N'EvfolyamTipus' 
    ,DIB.C_CODE = N'001' 
    ,DIB.C_PROTECTED = N'T' 
    ,DIB.C_ORDER = 481 
  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.ID = 7883;
  END IF @TEMP_EnvironmentName = 'NSZFH'
  BEGIN 
  INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
  SELECT DIB.ID, 7883, 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'EvfolyamTipus' AND DIB.C_NAME = N'1/13 5-ös szintű technikum' 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'EvfolyamTipus' AND DIB.C_NAME = N'1/13 5-ös szintű technikum' AND DIB.TOROLT = 'F' 
  UPDATE DIB SET DIB.TOROLT = 'F'     ,DIB.C_NAME = N'1/13 5-ös szintű technikum' 
    ,DIB.C_NAME_1 = N'1/13 5-ös szintű technikum' 
    ,DIB.C_NAME_4 = N'13' 
    ,DIB.C_TYPE = N'EvfolyamTipus' 
    ,DIB.C_CODE = N'001' 
    ,DIB.C_PROTECTED = N'T' 
    ,DIB.C_ORDER = 481 
  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.ID = 7883;
  END IF @TEMP_EnvironmentName = 'HOI'
  BEGIN 
  INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
  SELECT DIB.ID, 7883, 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'EvfolyamTipus' AND DIB.C_NAME = N'1/13 5-ös szintű technikum' 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'EvfolyamTipus' AND DIB.C_NAME = N'1/13 5-ös szintű technikum' AND DIB.TOROLT = 'F' 
  UPDATE DIB SET DIB.TOROLT = 'F'     ,DIB.C_NAME = N'1/13 5-ös szintű technikum' 
    ,DIB.C_NAME_1 = N'1/13 5-ös szintű technikum' 
    ,DIB.C_NAME_4 = N'13' 
    ,DIB.C_TYPE = N'EvfolyamTipus' 
    ,DIB.C_CODE = N'001' 
    ,DIB.C_PROTECTED = N'T' 
    ,DIB.C_ORDER = 481 
  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.ID = 7883;
  END IF @TEMP_EnvironmentName = 'AZURE'
  BEGIN 
  INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
  SELECT DIB.ID, 7883, 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'EvfolyamTipus' AND DIB.C_NAME = N'1/13 5-ös szintű technikum' 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'EvfolyamTipus' AND DIB.C_NAME = N'1/13 5-ös szintű technikum' AND DIB.TOROLT = 'F' 
  UPDATE DIB SET DIB.TOROLT = 'F'     ,DIB.C_NAME = N'1/13 5-ös szintű technikum' 
    ,DIB.C_NAME_1 = N'1/13 5-ös szintű technikum' 
    ,DIB.C_NAME_4 = N'13' 
    ,DIB.C_TYPE = N'EvfolyamTipus' 
    ,DIB.C_CODE = N'001' 
    ,DIB.C_PROTECTED = N'T' 
    ,DIB.C_ORDER = 481 
  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.ID = 7883;
  END
 EXEC [dev].[uspCreateDictionaryItems] NULL, NULL
 EXEC [dev].uspSwitchDictionaryItemBaseFromTmp 