﻿UPDATE tcs
SET tcs.C_TANULOID = kovTanevF.ID
   ,tcs.LASTCHANGED = GETDATE()
   ,tcs.SERIAL += 1
   ,tcs.MODIFIER = 0
FROM T_TANULOCSOPORT tcs
INNER JOIN T_FELHASZNALO f ON f.ID = tcs.C_TANULOID AND tcs.C_TANEVID <> f.C_TANEVID
INNER JOIN T_TANEV aktTanev ON aktTanev.ID = f.C_TANEVID AND aktTanev.C_AKTIV = 'T' AND aktTanev.C_NEV = '2019/2020' AND aktTanev.TOROLT = 'F'
INNER JOIN T_FELHASZNALO kovTanevF ON kovTanevF.C_OKTATASIAZONOSITO = f.C_OKTATASIAZONOSITO AND kovTanevF.TOROLT = 'F'
INNER JOIN T_TANEV kovTanev ON kovTanev.ID = kovTanevF.C_TANEVID AND kovTanev.C_INTEZMENYID = aktTanev.C_INTEZMENYID AND kovTanev.C_KOVETKEZO = 'T' AND kovTanev.C_NEV = '2020/2021' AND kovTanev.TOROLT = 'F'
WHERE tcs.C_TANEVID = kovTanev.ID
