﻿UPDATE t
SET
  t.C_ORARENDIORAGROUPID = o.C_ORARENDIORAGROUPID
FROM T_TANITASIORA t
JOIN T_ORAK_TANAROK ot ON t.ID = ot.C_ORAKID
JOIN T_ORARENDIORA o ON
  o.C_ORASZAM = t.C_ORASZAM
  and o.C_HETNAPJA = t.C_HETNAPJA
  and o.C_CSENGETESIRENDORAID = t.C_CSENGETESIRENDORAID
  and o.C_TANTARGYID = t.C_TANTARGYID
  and o.C_TEREMID = t.C_TEREMID
  and o.C_OSZTALYCSOPORTID = t.C_OSZTALYCSOPORTID
  and o.C_FOGLALKOZASID = t.C_FOGLALKOZASID
  and o.C_TANARID = ot.C_TANAROKID
  and o.C_ORAERVENYESSEGKEZDETE <= t.C_DATUM AND o.C_ORAERVENYESSEGVEGE > t.C_DATUM
where
  t.C_ORARENDIORAGROUPID = 0 and t.TOROLT = 'F' and o.TOROLT = 'F'