﻿UPDATE oo SET 
	 C_FOGLALKOZASID = NULL
	,MODIFIER = 0
	,LASTCHANGED = GETDATE()
FROM T_ORARENDIORA oo
	INNER JOIN T_INTEZMENY i ON i.ID = oo.C_INTEZMENYID AND i.TOROLT='F'
	INNER JOIN T_TANEV tn ON tn.ID = oo.C_TANEVID AND tn.TOROLT='F' AND tn.C_AKTIV = 'T'
	INNER JOIN T_FOGLALKOZAS f ON f.ID = oo.C_FOGLALKOZASID AND f.TOROLT='F'
		AND (f.C_TANARID <> oo.C_TANARID
		  OR f.C_OSZTALYCSOPORTID <> oo.C_OSZTALYCSOPORTID
		  OR f.C_TANTARGYID <> oo.C_TANTARGYID
    )
WHERE oo.TOROLT='F' 