﻿DECLARE 
   @intezmenyId int
  ,@tanevId int
  ,@sql nvarchar(max)
  ,@azonosito nvarchar(50)

DECLARE TanevCur CURSOR LOCAL FOR
SELECT i.ID, tv.ID, i.C_AZONOSITO FROM T_INTEZMENY i
INNER JOIN T_TANEV tv ON tv.C_INTEZMENYID = i.ID AND tv.C_AKTIV = 'T' AND tv.TOROLT = 'F'
WHERE i.TOROLT = 'F'

OPEN TanevCur
FETCH NEXT FROM TanevCur
INTO @intezmenyId, @tanevId, @azonosito


WHILE @@FETCH_STATUS = 0 BEGIN

  EXEC uspGenerateOrarend
     @pIntezmenyId = @intezmenyId
    ,@pTanevId = @tanevId
    ,@pIdoszakKezdete = NULL
    ,@pIdoszakVege = NULL
    ,@pOrarendiOraId = NULL
    ,@pOsztalycsoportId = NULL

  FETCH NEXT FROM TanevCur
  INTO @intezmenyId, @tanevId, @azonosito

END

CLOSE TanevCur
DEALLOCATE TanevCur
GO