﻿
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, 8160, 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 = '2020/2021'
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Nukleáris szakasszisztens (2020)' 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 = '2020/2021' 
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Nukleáris szakasszisztens (2020)' AND DIB.TOROLT = 'F' 
  UPDATE DIB SET DIB.TOROLT = 'F'     ,DIB.C_NAME = N'Nukleáris szakasszisztens (2020)' 
    ,DIB.C_TYPE = N'SzakmairanyTipus' 
    ,DIB.C_VISIBLE = N'T' 
    ,DIB.C_ORDER = 3453 
  FROM T_DICTIONARYITEMBASE DIB 
  INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2020/2021' 
    WHERE DIB.ID = 8160;
  END IF @TEMP_EnvironmentName = 'NSZFH'
  BEGIN 
  INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
  SELECT DIB.ID, 8160, 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 = '2020/2021'
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Nukleáris szakasszisztens (2020)' 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 = '2020/2021' 
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Nukleáris szakasszisztens (2020)' AND DIB.TOROLT = 'F' 
  UPDATE DIB SET DIB.TOROLT = 'F'     ,DIB.C_NAME = N'Nukleáris szakasszisztens (2020)' 
    ,DIB.C_TYPE = N'SzakmairanyTipus' 
    ,DIB.C_VISIBLE = N'T' 
    ,DIB.C_ORDER = 3453 
  FROM T_DICTIONARYITEMBASE DIB 
  INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2020/2021' 
    WHERE DIB.ID = 8160;
  END IF @TEMP_EnvironmentName = 'HOI'
  BEGIN 
  INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
  SELECT DIB.ID, 8160, 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 = '2020/2021'
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Nukleáris szakasszisztens (2020)' 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 = '2020/2021' 
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Nukleáris szakasszisztens (2020)' AND DIB.TOROLT = 'F' 
  UPDATE DIB SET DIB.TOROLT = 'F'     ,DIB.C_NAME = N'Nukleáris szakasszisztens (2020)' 
    ,DIB.C_TYPE = N'SzakmairanyTipus' 
    ,DIB.C_VISIBLE = N'T' 
    ,DIB.C_ORDER = 3453 
  FROM T_DICTIONARYITEMBASE DIB 
  INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2020/2021' 
    WHERE DIB.ID = 8160;
  END IF @TEMP_EnvironmentName = 'AZURE'
  BEGIN 
  INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
  SELECT DIB.ID, 8160, 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 = '2020/2021'
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Nukleáris szakasszisztens (2020)' 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 = '2020/2021' 
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Nukleáris szakasszisztens (2020)' AND DIB.TOROLT = 'F' 
  UPDATE DIB SET DIB.TOROLT = 'F'     ,DIB.C_NAME = N'Nukleáris szakasszisztens (2020)' 
    ,DIB.C_TYPE = N'SzakmairanyTipus' 
    ,DIB.C_VISIBLE = N'T' 
    ,DIB.C_ORDER = 3453 
  FROM T_DICTIONARYITEMBASE DIB 
  INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2020/2021' 
    WHERE DIB.ID = 8160;
  END IF @TEMP_EnvironmentName = 'KK'
  BEGIN 
  INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
  SELECT DIB.ID, 8161, 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 = '2020/2021'
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Sugárterápiás szakasszisztens (2020)' 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 = '2020/2021' 
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Sugárterápiás szakasszisztens (2020)' AND DIB.TOROLT = 'F' 
  UPDATE DIB SET DIB.TOROLT = 'F'     ,DIB.C_NAME = N'Sugárterápiás szakasszisztens (2020)' 
    ,DIB.C_TYPE = N'SzakmairanyTipus' 
    ,DIB.C_VISIBLE = N'T' 
    ,DIB.C_ORDER = 3455 
  FROM T_DICTIONARYITEMBASE DIB 
  INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2020/2021' 
    WHERE DIB.ID = 8161;
  END IF @TEMP_EnvironmentName = 'NSZFH'
  BEGIN 
  INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
  SELECT DIB.ID, 8161, 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 = '2020/2021'
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Sugárterápiás szakasszisztens (2020)' 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 = '2020/2021' 
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Sugárterápiás szakasszisztens (2020)' AND DIB.TOROLT = 'F' 
  UPDATE DIB SET DIB.TOROLT = 'F'     ,DIB.C_NAME = N'Sugárterápiás szakasszisztens (2020)' 
    ,DIB.C_TYPE = N'SzakmairanyTipus' 
    ,DIB.C_VISIBLE = N'T' 
    ,DIB.C_ORDER = 3455 
  FROM T_DICTIONARYITEMBASE DIB 
  INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2020/2021' 
    WHERE DIB.ID = 8161;
  END IF @TEMP_EnvironmentName = 'HOI'
  BEGIN 
  INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
  SELECT DIB.ID, 8161, 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 = '2020/2021'
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Sugárterápiás szakasszisztens (2020)' 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 = '2020/2021' 
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Sugárterápiás szakasszisztens (2020)' AND DIB.TOROLT = 'F' 
  UPDATE DIB SET DIB.TOROLT = 'F'     ,DIB.C_NAME = N'Sugárterápiás szakasszisztens (2020)' 
    ,DIB.C_TYPE = N'SzakmairanyTipus' 
    ,DIB.C_VISIBLE = N'T' 
    ,DIB.C_ORDER = 3455 
  FROM T_DICTIONARYITEMBASE DIB 
  INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2020/2021' 
    WHERE DIB.ID = 8161;
  END IF @TEMP_EnvironmentName = 'AZURE'
  BEGIN 
  INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE) 
  SELECT DIB.ID, 8161, 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 = '2020/2021'
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Sugárterápiás szakasszisztens (2020)' 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 = '2020/2021' 
    WHERE DIB.C_TYPE = N'SzakmairanyTipus' AND DIB.C_NAME = N'Sugárterápiás szakasszisztens (2020)' AND DIB.TOROLT = 'F' 
  UPDATE DIB SET DIB.TOROLT = 'F'     ,DIB.C_NAME = N'Sugárterápiás szakasszisztens (2020)' 
    ,DIB.C_TYPE = N'SzakmairanyTipus' 
    ,DIB.C_VISIBLE = N'T' 
    ,DIB.C_ORDER = 3455 
  FROM T_DICTIONARYITEMBASE DIB 
  INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2020/2021' 
    WHERE DIB.ID = 8161;
  END
 EXEC [dev].[uspCreateDictionaryItems] NULL, NULL 
 EXEC [dev].uspSwitchDictionaryItemBaseFromTmp  
 
 -- 8157 Intervenciós szakasszisztens (2020) 
 UPDATE DIB SET DIB.C_ORDER = 3454 
  FROM T_DICTIONARYITEMBASE DIB 
    INNER JOIN T_TANEV t ON t.ID = DIB.C_TANEVID AND t.TOROLT = 'F' AND t.C_NEV = '2020/2021' 
    WHERE DIB.ID = 8157

UPDATE T_DICTIONARYITEMBASE SET C_NAME_1 = C_NAME WHERE C_NAME_1 IS NULL AND ID < 100000