﻿SELECT ID 
INTO #deleteDict
FROM T_DICTIONARYITEMBASE
WHERE C_NAME = 'Tanító' 
  AND ID > 100000
  AND C_TYPE = 'MunkakorTipus' 
  AND TOROLT = 'F'

UPDATE T_DICTIONARYITEMBASE
  SET TOROLT = 'T'
WHERE ID IN (SELECT ID FROM #deleteDict)

UPDATE T_MUNKAKORTIPUS
  SET TOROLT = 'T'
WHERE ID IN (SELECT ID FROM #deleteDict)

DECLARE intezmenytanevekCursor CURSOR LOCAL FOR 
	SELECT C_INTEZMENYID, C_TANEVID
		FROM T_INTEZMENYADATOK

DECLARE @intezmenyId int, @tanevId int

OPEN intezmenytanevekCursor  
FETCH NEXT FROM intezmenytanevekCursor INTO @intezmenyId, @tanevId

WHILE @@FETCH_STATUS = 0 
BEGIN  
	PRINT N'INTÉZMÉNY ID: ' + CAST(@intezmenyId AS NVARCHAR(10)) + N', TANÉV ID: ' + CAST(@tanevId AS NVARCHAR(10))
    EXEC sp_Global_CreateDictionaryItems @IntezmenyId = @intezmenyId, @TanevId = @tanevId

	FETCH NEXT FROM intezmenytanevekCursor INTO @intezmenyId, @tanevId
END  

CLOSE intezmenytanevekCursor  
DEALLOCATE intezmenytanevekCursor

GO

UPDATE T_MUNKAUGYIADATOK
  SET C_MUNKAKORTIPUSA = 6725
WHERE C_MUNKAKORTIPUSA IN (SELECT ID FROM #deleteDict)

UPDATE T_TOVABBIMUNKAUGYIADATOK
  SET C_MUNKAKORTIPUSA = 6725
WHERE C_MUNKAKORTIPUSA IN (SELECT ID FROM #deleteDict)

DROP TABLE #deleteDict

GO