﻿UPDATE
  orarendiOra
SET  
   orarendiOra.C_TANTARGYID = fogl.C_TANTARGYID
  ,orarendiOra.MODIFIER = 0
  ,LASTCHANGED = GETDATE() 
FROM
  T_ORARENDIORA orarendiOra
  LEFT JOIN T_FOGLALKOZAS fogl on fogl.ID = orarendiOra.C_FOGLALKOZASID
  INNER JOIN T_TANEV tanev ON tanev.ID = orarendiOra.C_TANEVID
WHERE
  orarendiOra.C_TANTARGYID IS NOT NULL
  AND orarendiOra.C_TANTARGYID <> fogl.C_TANTARGYID
  AND orarendiOra.TOROLT ='F' and fogl.TOROLT ='F'
  AND tanev.C_AKTIV = 'T'