﻿DECLARE @tanevId INT

DECLARE tanevCursor CURSOR FAST_FORWARD READ_ONLY FOR 
SELECT tv.ID 
FROM T_TANEV tv 
  INNER JOIN T_INTEZMENYADATOK ia ON ia.C_TANEVID = tv.ID AND ia.TOROLT = 'F'
  INNER JOIN T_INTEZMENY i ON i.ID = ia.C_INTEZMENYID AND i.TOROLT = 'F'
WHERE tv.TOROLT = 'F' 
  AND tv.C_NEV = '2021/2022'
  AND ia.C_ISSZAKKEPZO = 'T'

OPEN tanevCursor

FETCH NEXT FROM tanevCursor 
INTO @tanevId

WHILE @@FETCH_STATUS = 0
BEGIN

  UPDATE tta SET 
    tta.C_TANTERVIJELLEGID = IIF(ocs.C_KEPZESIFORMA IN (1103,1101,1102,1104,5448,1100,1105), 8827, ocs.C_KEPZESIFORMA)
  FROM T_TANULOTANUGYIADATOK tta
    INNER JOIN T_TANULOCSOPORT tcs ON tcs.ID = tta.C_TANULOCSOPORTID
    INNER JOIN T_OSZTALYCSOPORT ocs ON ocs.ID = tcs.C_OSZTALYCSOPORTID
  WHERE tta.TOROLT = 'F'
    AND tta.C_TANEVID = @tanevId

  FETCH NEXT FROM tanevCursor 
  INTO @tanevId
END

CLOSE tanevCursor
DEALLOCATE tanevCursor
GO