﻿--Migration
UPDATE cs
SET cs.C_CSOPORTVEZETOID = a.ID
   ,cs.MODIFIER = 0
   ,cs.LASTCHANGED = GETDATE()
   ,cs.SERIAL += 1
FROM T_csoport cs
INNER JOIN T_ALKALMAZOTT a on a.ELOZOTANEVIREKORDID = cs.C_CSOPORTVEZETOID
WHERE cs.C_ALTANEVID <> a.C_ALTANEVID

DELETE duf
FROM T_DASHBOARDUZENETFELHASZNALO duf
INNER JOIN T_GONDVISELO g on g.ID = duf.C_GONDVISELOID
INNER JOIN T_TANEV t on t.ID = duf.C_TANEVID 
WHERE g.C_TANEVID <> duf.C_TANEVID AND t.C_AKTIV = 'F'

UPDATE kir
SET kir.C_INTEZMENYADATOKID = a2.ID
   ,kir.MODIFIER = 0
   ,kir.LASTCHANGED = GETDATE()
   ,kir.SERIAL += 1
FROM T_KIRTELEPHELY kir WITH (NOLOCK)
INNER JOIN T_INTEZMENYADATOK a WITH (NOLOCK) ON a.ID = kir.C_INTEZMENYADATOKID
INNER JOIN T_INTEZMENYADATOK a2 WITH (NOLOCK) ON a2.C_TANEVID = kir.C_TANEVID
WHERE a.C_TANEVID <> kir.C_TANEVID

UPDATE oro
SET TOROLT = 'T'
FROM T_ORARENDIORA oro WITH (NOLOCK)
INNER JOIN T_OSZTALYCSOPORT a WITH (NOLOCK) ON a.ID = oro.C_OSZTALYCSOPORTID
WHERE a.C_TANEVID <> oro.C_TANEVID

DELETE fb
FROM T_FELHASZNALOBELEPES fb WITH (NOLOCK)
INNER JOIN T_FELHASZNALO a WITH (NOLOCK) ON a.ID = fb.C_FELHASZNALOID
INNER JOIN T_TANEV t on t.ID = fb.C_TANEVID 
WHERE a.C_TANEVID <> fb.C_TANEVID AND t.C_AKTIV = 'F'

DELETE fb
FROM T_FELHASZNALOBELEPES fb WITH (NOLOCK)
INNER JOIN T_GONDVISELO a WITH (NOLOCK) ON a.ID = fb.C_GONDVISELOID
INNER JOIN T_TANEV t on t.ID = fb.C_TANEVID 
WHERE a.C_TANEVID <> fb.C_TANEVID AND t.C_AKTIV = 'F'
