﻿
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 [Value] 
FROM dev.EnvironmentInfo WHERE [Key] = 'Dictionary')
IF (@TEMP_EnvironmentName IS NULL OR @TEMP_EnvironmentName NOT IN ('KK','NSZFH','HOI','AZURE'))
BEGIN  INSERT INTO T_DICTIONARYITEMBASE(C_VALUE) VALUES('Nincs Dictionary ertek a dev.EnvironmentInfo tablaban') END  -- elszall a migracio ha nincs 

IF @TEMP_EnvironmentName = 'KK'
  BEGIN 
    -----  8677 ----- Na -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8677, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 172 AND DIB.C_NAME = N'Na' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 172 AND DIB.C_NAME = N'Na' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'NSZFH'
  BEGIN 
    -----  8677 ----- Na -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8677, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 172 AND DIB.C_NAME = N'Na' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 172 AND DIB.C_NAME = N'Na' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'HOI'
  BEGIN 
    -----  8677 ----- Na -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8677, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 172 AND DIB.C_NAME = N'Na' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 172 AND DIB.C_NAME = N'Na' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'AZURE'
  BEGIN 
    -----  8677 ----- Na -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8677, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 172 AND DIB.C_NAME = N'Na' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 172 AND DIB.C_NAME = N'Na' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'KK'
  BEGIN 
    -----  8678 ----- Klasszikus zene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8678, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Klasszikus zene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Klasszikus zene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'NSZFH'
  BEGIN 
    -----  8678 ----- Klasszikus zene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8678, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Klasszikus zene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Klasszikus zene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'HOI'
  BEGIN 
    -----  8678 ----- Klasszikus zene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8678, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Klasszikus zene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Klasszikus zene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'AZURE'
  BEGIN 
    -----  8678 ----- Klasszikus zene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8678, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Klasszikus zene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Klasszikus zene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'KK'
  BEGIN 
    -----  8679 ----- Népzene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8679, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Népzene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Népzene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'NSZFH'
  BEGIN 
    -----  8679 ----- Népzene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8679, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Népzene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Népzene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'HOI'
  BEGIN 
    -----  8679 ----- Népzene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8679, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Népzene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Népzene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'AZURE'
  BEGIN 
    -----  8679 ----- Népzene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8679, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Népzene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Népzene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'KK'
  BEGIN 
    -----  8680 ----- Jazz-zene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8680, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Jazz-zene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Jazz-zene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'NSZFH'
  BEGIN 
    -----  8680 ----- Jazz-zene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8680, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Jazz-zene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Jazz-zene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'HOI'
  BEGIN 
    -----  8680 ----- Jazz-zene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8680, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Jazz-zene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Jazz-zene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'AZURE'
  BEGIN 
    -----  8680 ----- Jazz-zene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8680, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Jazz-zene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Jazz-zene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'KK'
  BEGIN 
    -----  8681 ----- Elektroakusztikus zene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8681, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Elektroakusztikus zene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Elektroakusztikus zene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'NSZFH'
  BEGIN 
    -----  8681 ----- Elektroakusztikus zene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8681, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Elektroakusztikus zene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Elektroakusztikus zene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'HOI'
  BEGIN 
    -----  8681 ----- Elektroakusztikus zene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8681, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Elektroakusztikus zene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Elektroakusztikus zene' AND DIB.TOROLT = 'F' 
END 

IF @TEMP_EnvironmentName = 'AZURE'
  BEGIN 
    -----  8681 ----- Elektroakusztikus zene -----
    INSERT INTO tmpForSwitchDictionaryItemBase(RegiID, UjID, TanevID, C_NAME, C_TYPE)
    SELECT DIB.ID, 8681, DIB.C_TANEVID, DIB.C_NAME, DIB.C_TYPE
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Elektroakusztikus zene' AND DIB.TOROLT = 'F' 
    UPDATE DIB SET 
    DIB.TOROLT = 'T' 
    FROM T_DICTIONARYITEMBASE DIB 
      WHERE DIB.C_DICTIONARYTYPEID = 171 AND DIB.C_NAME = N'Elektroakusztikus zene' AND DIB.TOROLT = 'F' 
END 
;
 DISABLE TRIGGER ALL ON T_DICTIONARYITEMBASE;  
 EXEC [dev].[uspCreateDictionaryItems] NULL, NULL; 
 ENABLE TRIGGER ALL ON T_DICTIONARYITEMBASE;  
 EXEC [dev].uspSwitchDictionaryItemBaseFromTmp;  