﻿DECLARE @lekerdezesDatuma nvarchar(12) = CONVERT(nvarchar, GETDATE(), 23)

DECLARE tanevCursor CURSOR LOCAL FOR 
  SELECT t.ID AS TanevId, telozo.ID AS ElozoTanevId
  FROM T_TANEV t
    INNER JOIN T_TANEV telozo ON telozo.C_INTEZMENYID = t.C_INTEZMENYID AND telozo.TOROLT = 'F'
WHERE t.C_AKTIV = 'T' 
  AND t.C_SORSZAM = 42
  AND t.TOROLT = 'F'
  AND telozo.C_SORSZAM = t.C_SORSZAM - 2

DECLARE @tanevId int
  ,@elozoTanevId int

OPEN tanevCursor
FETCH NEXT FROM tanevCursor INTO @tanevId, @elozoTanevId
WHILE @@FETCH_STATUS = 0 BEGIN
  EXEC uspUpdateSzamitottAtlagEvvegi 
     @pTanevId = @elozoTanevId
    ,@pKovTanevId = @tanevId
    ,@pFelhasznaloId = 0

  EXEC uspUpdateTanuloSzakkepzesiJuttatasok
    @pTanevId = @tanevId
    ,@pMaxIgazolatlanokSzama = 6
    ,@pMinOsztondijAtlag = 2.00
    ,@pOsztondijAlap = 167400
    ,@pLekerdezesDatuma = @lekerdezesDatuma
    ,@pFelhasznaloId = 0
    
  FETCH NEXT FROM tanevCursor INTO @tanevId, @elozoTanevId
END

CLOSE tanevCursor
DEALLOCATE tanevCursor
