﻿update oo1
set C_ORARENDIORAGROUPID = oo1.ID, MODIFIER = 0, LASTCHANGED = GETDATE(), SERIAL += 1
--select oo1.ID - oo1.C_ORARENDIORAGROUPID as Dif, oo1.C_ORARENDIORAGROUPID, oo1.ID, oo1.CREATED, te.C_AKTIVALVA, *
from T_ORARENDIORA oo1
inner join T_ORARENDIORA oo2 on oo1.C_ORARENDIORAGROUPID = oo2.ID and oo2.TOROLT = 'F'
inner join T_TANEV te on te.ID = oo1.C_TANEVID and te.TOROLT = 'F' and te.C_NEV = '2021/2022'
where oo1.TOROLT = 'F'
  and oo1.C_ORARENDIORAGROUPID <> oo1.ID
  and not (oo1.C_HETNAPJA = oo2.C_HETNAPJA 
       and oo1.C_ORASZAM  = oo2.C_ORASZAM
       and oo1.C_TANARID  = oo2.C_TANARID
       and oo1.C_OSZTALYCSOPORTID = oo2.C_OSZTALYCSOPORTID
       and oo1.C_TANTARGYID = oo2.C_TANTARGYID)
  and oo1.C_EGYEDINAP = 'F'
  --and oo1.CREATED < te.C_AKTIVALVA
  and not exists (select 1 from T_ORARENDIORA oo3 where oo3.C_ORARENDIORAGROUPID = oo1.ID and oo3.TOROLT = 'F')
  and not exists (select 1 from T_HELYETTESITESIIDOSZAK hi where hi.C_GROUPID = oo1.C_ORARENDIORAGROUPID and hi.TOROLT = 'F')
  and not exists (select 1 from T_SZAMONKERESELOREJELZES sze where sze.C_ORARENDIORAGROUPID = oo1.C_ORARENDIORAGROUPID and sze.TOROLT = 'F')
--order by oo1.ID