﻿--Migration
UPDATE ta
SET    ta.C_AGAZATALAPOKTMEGNEVTIPUSID = ta2.C_AGAZATALAPOKTMEGNEVTIPUSID
      ,ta.MODIFIER = 0
      ,ta.LASTCHANGED = GETDATE()
      ,ta.SERIAL += 1
FROM T_TANULOTANUGYIADATOK ta
INNER JOIN T_TANULOCSOPORT tcs on ta.C_TANULOCSOPORTID = tcs.ID and tcs.TOROLT = 'F'
INNER JOIN T_FELHASZNALO t on t.ID = tcs.C_TANULOID and t.TOROLT = 'F'
INNER JOIN T_TANEV te on te.ID = tcs.C_TANEVID AND te.C_NEV = '2022/2023' AND te.TOROLT = 'F'
INNER JOIN T_FELHASZNALO t2 on t2.ID = t.ELOZOTANEVIREKORDID and t2.TOROLT = 'F'
INNER JOIN T_TANULOCSOPORT tcs2 on tcs2.C_TANULOID = t2.ID AND tcs2.TOROLT = 'F'
INNER JOIN T_TANULOTANUGYIADATOK ta2 on ta2.C_TANULOCSOPORTID = tcs2.ID AND ta2.TOROLT = 'F'
INNER JOIN T_TANEV te2 on te2.ID = tcs2.C_TANEVID AND te2.C_NEV = '2021/2022' AND te2.TOROLT = 'F'
WHERE ta.TOROLT = 'F'
  and ta.C_AGAZATALAPOKTMEGNEVTIPUSID is null
  and ta2.C_AGAZATALAPOKTMEGNEVTIPUSID is not null
  and tcs2.C_KILEPESDATUM = '2022-08-31'

UPDATE ta
SET    ta.C_AGAZATALAPVIZSGAEREDTIPUSID = ta2.C_AGAZATALAPVIZSGAEREDTIPUSID
      ,ta.MODIFIER = 0
      ,ta.LASTCHANGED = GETDATE()
      ,ta.SERIAL += 1
FROM T_TANULOTANUGYIADATOK ta
INNER JOIN T_TANULOCSOPORT tcs on ta.C_TANULOCSOPORTID = tcs.ID and tcs.TOROLT = 'F'
INNER JOIN T_FELHASZNALO t on t.ID = tcs.C_TANULOID and t.TOROLT = 'F'
INNER JOIN T_TANEV te on te.ID = tcs.C_TANEVID AND te.C_NEV = '2022/2023' AND te.TOROLT = 'F'
INNER JOIN T_FELHASZNALO t2 on t2.ID = t.ELOZOTANEVIREKORDID and t2.TOROLT = 'F'
INNER JOIN T_TANULOCSOPORT tcs2 on tcs2.C_TANULOID = t2.ID AND tcs2.TOROLT = 'F'
INNER JOIN T_TANULOTANUGYIADATOK ta2 on ta2.C_TANULOCSOPORTID = tcs2.ID AND ta2.TOROLT = 'F'
INNER JOIN T_TANEV te2 on te2.ID = tcs2.C_TANEVID AND te2.C_NEV = '2021/2022' AND te2.TOROLT = 'F'
WHERE ta.TOROLT = 'F'
  and ta.C_AGAZATALAPVIZSGAEREDTIPUSID is null
  and ta2.C_AGAZATALAPVIZSGAEREDTIPUSID is not null
  and tcs2.C_KILEPESDATUM = '2022-08-31'

UPDATE ta
SET    ta.C_AGAZATIALAPVIZSGATELJESITES = ta2.C_AGAZATIALAPVIZSGATELJESITES
      ,ta.MODIFIER = 0
      ,ta.LASTCHANGED = GETDATE()
      ,ta.SERIAL += 1
FROM T_TANULOTANUGYIADATOK ta
INNER JOIN T_TANULOCSOPORT tcs on ta.C_TANULOCSOPORTID = tcs.ID and tcs.TOROLT = 'F'
INNER JOIN T_FELHASZNALO t on t.ID = tcs.C_TANULOID and t.TOROLT = 'F'
INNER JOIN T_TANEV te on te.ID = tcs.C_TANEVID AND te.C_NEV = '2022/2023' AND te.TOROLT = 'F'
INNER JOIN T_FELHASZNALO t2 on t2.ID = t.ELOZOTANEVIREKORDID and t2.TOROLT = 'F'
INNER JOIN T_TANULOCSOPORT tcs2 on tcs2.C_TANULOID = t2.ID AND tcs2.TOROLT = 'F'
INNER JOIN T_TANULOTANUGYIADATOK ta2 on ta2.C_TANULOCSOPORTID = tcs2.ID AND ta2.TOROLT = 'F'
INNER JOIN T_TANEV te2 on te2.ID = tcs2.C_TANEVID AND te2.C_NEV = '2021/2022' AND te2.TOROLT = 'F'
WHERE ta.TOROLT = 'F'
  and ta.C_AGAZATIALAPVIZSGATELJESITES is null
  and ta2.C_AGAZATIALAPVIZSGATELJESITES is not null
  and tcs2.C_KILEPESDATUM = '2022-08-31'

UPDATE ta
SET    ta.C_AGAZATIALAPVIZSGAEREDMENYE = ta2.C_AGAZATIALAPVIZSGAEREDMENYE
      ,ta.MODIFIER = 0
      ,ta.LASTCHANGED = GETDATE()
      ,ta.SERIAL += 1
FROM T_TANULOTANUGYIADATOK ta
INNER JOIN T_TANULOCSOPORT tcs on ta.C_TANULOCSOPORTID = tcs.ID and tcs.TOROLT = 'F'
INNER JOIN T_FELHASZNALO t on t.ID = tcs.C_TANULOID and t.TOROLT = 'F'
INNER JOIN T_TANEV te on te.ID = tcs.C_TANEVID AND te.C_NEV = '2022/2023' AND te.TOROLT = 'F'
INNER JOIN T_FELHASZNALO t2 on t2.ID = t.ELOZOTANEVIREKORDID and t2.TOROLT = 'F'
INNER JOIN T_TANULOCSOPORT tcs2 on tcs2.C_TANULOID = t2.ID AND tcs2.TOROLT = 'F'
INNER JOIN T_TANULOTANUGYIADATOK ta2 on ta2.C_TANULOCSOPORTID = tcs2.ID AND ta2.TOROLT = 'F'
INNER JOIN T_TANEV te2 on te2.ID = tcs2.C_TANEVID AND te2.C_NEV = '2021/2022' AND te2.TOROLT = 'F'
WHERE ta.TOROLT = 'F'
  and ta.C_AGAZATIALAPVIZSGAEREDMENYE is null
  and ta2.C_AGAZATIALAPVIZSGAEREDMENYE is not null
  and tcs2.C_KILEPESDATUM = '2022-08-31'

UPDATE ta
SET    ta.C_AGAZATIALAPVIZSGAEREDMENYESZ = ta2.C_AGAZATIALAPVIZSGAEREDMENYESZ
      ,ta.MODIFIER = 0
      ,ta.LASTCHANGED = GETDATE()
      ,ta.SERIAL += 1
FROM T_TANULOTANUGYIADATOK ta
INNER JOIN T_TANULOCSOPORT tcs on ta.C_TANULOCSOPORTID = tcs.ID and tcs.TOROLT = 'F'
INNER JOIN T_FELHASZNALO t on t.ID = tcs.C_TANULOID and t.TOROLT = 'F'
INNER JOIN T_TANEV te on te.ID = tcs.C_TANEVID AND te.C_NEV = '2022/2023' AND te.TOROLT = 'F'
INNER JOIN T_FELHASZNALO t2 on t2.ID = t.ELOZOTANEVIREKORDID and t2.TOROLT = 'F'
INNER JOIN T_TANULOCSOPORT tcs2 on tcs2.C_TANULOID = t2.ID AND tcs2.TOROLT = 'F'
INNER JOIN T_TANULOTANUGYIADATOK ta2 on ta2.C_TANULOCSOPORTID = tcs2.ID AND ta2.TOROLT = 'F'
INNER JOIN T_TANEV te2 on te2.ID = tcs2.C_TANEVID AND te2.C_NEV = '2021/2022' AND te2.TOROLT = 'F'
WHERE ta.TOROLT = 'F'
  and ta.C_AGAZATIALAPVIZSGAEREDMENYESZ is null
  and ta2.C_AGAZATIALAPVIZSGAEREDMENYESZ is not null
  and tcs2.C_KILEPESDATUM = '2022-08-31'