﻿DECLARE @TypeId int

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))

	IF (@TypeId IS NULL) BEGIN
		SELECT @TypeId = ID
		FROM T_DICTIONARYTYPE
		WHERE C_CODENAME = N'KozmuSzamlaTipus'
	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
	        (6923, N'Villany', N'Villany', NULL, NULL, NULL, N'KozmuSzamlaTipus', N'T', N'T', 1, NULL, 1, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6924, N'Gáz', N'Gáz', NULL, NULL, NULL, N'KozmuSzamlaTipus', N'T', N'T', 2, NULL, 2, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6925, N'Víz', N'Víz', NULL, NULL, NULL, N'KozmuSzamlaTipus', N'T', N'T', 3, NULL, 3, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6926, N'Csatorna', N'Csatorna', NULL, NULL, NULL, N'KozmuSzamlaTipus', N'T', N'T', 4, NULL, 4, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6927, N'Szemétszállítás', N'Szemétszállítás', NULL, NULL, NULL, N'KozmuSzamlaTipus', N'T', N'T', 5, NULL, 5, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6928, N'Telekommunikáció', N'Telekommunikáció', NULL, NULL, NULL, N'KozmuSzamlaTipus', N'T', N'T', 6, NULL, 6, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6929, N'Telefon', N'Telefon', NULL, NULL, NULL, N'KozmuSzamlaTipus', N'T', N'T', 7, NULL, 7, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6930, N'Televízió', N'Televízió', NULL, NULL, NULL, N'KozmuSzamlaTipus', N'T', N'T', 8, NULL, 8, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6931, N'Internet', N'Internet', NULL, NULL, NULL, N'KozmuSzamlaTipus', N'T', N'T', 9, NULL, 9, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL),
            (6932, N'Egyéb', N'Egyéb', NULL, NULL, NULL, N'KozmuSzamlaTipus', N'T', N'T', 10, NULL, 10, NULL, @TypeId, @IntezmenyId, @TanevId, 'F', 0, GETDATE(), GETDATE(), NULL, NULL)

    SET IDENTITY_INSERT [dbo].[T_DICTIONARYITEMBASE] OFF

		INSERT INTO [dbo].[T_KOZMUSZAMLATIPUS] ([ID], [C_ALINTEZMENYID], [C_ALTANEVID]) VALUES
			(6923, @IntezmenyId, @TanevId),
			(6924, @IntezmenyId, @TanevId),
			(6925, @IntezmenyId, @TanevId),
			(6926, @IntezmenyId, @TanevId),
			(6927, @IntezmenyId, @TanevId),
			(6928, @IntezmenyId, @TanevId),
			(6929, @IntezmenyId, @TanevId),
			(6930, @IntezmenyId, @TanevId),
			(6931, @IntezmenyId, @TanevId),
			(6932, @IntezmenyId, @TanevId)

	FETCH NEXT FROM intezmenytanevekCursor INTO @intezmenyId, @tanevId
END  

CLOSE intezmenytanevekCursor  
DEALLOCATE intezmenytanevekCursor

GO
