﻿DECLARE @TypeId int

DECLARE intezmenytanevekCursor CURSOR LOCAL FOR 
	SELECT DISTINCT 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))

	IF (@TypeId IS NULL) BEGIN
		SELECT @TypeId = ID
		FROM T_DICTIONARYTYPE
		WHERE C_CODENAME = N'MunkakorTipus'
	END

	SET IDENTITY_INSERT [dbo].[T_DICTIONARYITEMBASE] ON

		INSERT INTO dbo.T_DICTIONARYITEMBASE (ID, C_NAME, C_NAME_1, C_NAME_2, C_NAME_3, C_NAME_4, C_TYPE, C_PROTECTED, C_VISIBLE, C_ORDER, C_CODE, C_VALUE, C_COLOR, C_DICTIONARYTYPEID, C_INTEZMENYID, C_TANEVID, TOROLT, SERIAL, LASTCHANGED, CREATED, MODIFIER, CREATOR)
		VALUES
            (7356, N'NOKS pedagógiai felügyelő', N'NOKS pedagógiai felügyelő', NULL, NULL, NULL, N'MunkakorTipus', N'T', N'T', 2, NULL, 195, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL)

    SET IDENTITY_INSERT [dbo].[T_DICTIONARYITEMBASE] OFF

		INSERT INTO [dbo].[T_MUNKAKORTIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]) VALUES
			(7356, @IntezmenyId, @TanevId)

	FETCH NEXT FROM intezmenytanevekCursor INTO @intezmenyId, @tanevId
END  

CLOSE intezmenytanevekCursor  
DEALLOCATE intezmenytanevekCursor

GO