﻿--Migration
UPDATE tcs18 SET
  tcs18.C_TORZSLAPSZAM = tcs17.C_TORZSLAPSZAM
FROM T_TANULOCSOPORT tcs17  
  INNER JOIN T_FELHASZNALO fh17 ON fh17.ID = tcs17.C_TANULOID AND fh17.TOROLT = 'F'
  INNER JOIN T_OSZTALY o17 ON o17.ID = tcs17.C_OSZTALYCSOPORTID AND o17.TOROLT = 'F'
  INNER JOIN T_TANEV t17 ON t17.ID = tcs17.C_TANEVID AND t17.C_NEV = '2017/2018' AND t17.TOROLT = 'F'
  INNER JOIN T_FELHASZNALO fh18 ON fh17.C_OKTATASIAZONOSITO = fh18.C_OKTATASIAZONOSITO AND fh18.C_INTEZMENYID = fh17.C_INTEZMENYID AND fh18.TOROLT = 'F'
  INNER JOIN T_TANULOCSOPORT tcs18 ON tcs18.C_TANULOID = fh18.ID AND tcs18.TOROLT = 'F'
  INNER JOIN T_OSZTALY o18 ON o18.ID = tcs18.C_OSZTALYCSOPORTID AND o18.TOROLT = 'F'
  INNER JOIN T_TANEV t18 ON t18.ID = tcs18.C_TANEVID AND t18.C_NEV = '2018/2019' AND t18.TOROLT = 'F'
WHERE tcs18.C_TORZSLAPSZAM IS NULL AND tcs17.C_TORZSLAPSZAM IS NOT NULL AND tcs17.TOROLT = 'F'
GO
