﻿UPDATE cst SET C_ORAPERC = 45
FROM T_CSOPORTTIPUS cst
	INNER JOIN T_TANEV tn ON tn.ID = cst.C_ALTANEVID AND tn.TOROLT = 'F' AND tn.C_NEV = '2018/2019'
	INNER JOIN T_INTEZMENY i ON i.ID = cst.C_ALINTEZMENYID AND i.TOROLT = 'F' AND i.C_FENNTARTOID<900
WHERE cst.C_ORAPERC IS NULL AND cst.TOROLT = 'F'

UPDATE oo SET C_ORAVEGE = DATEADD(MINUTE,ISNULL(cst.C_ORAPERC,45),C_ORAVEGE)
FROM T_ORARENDIORA oo
	INNER JOIN T_TANEV tn ON tn.ID = oo.C_TANEVID AND tn.TOROLT = 'F' AND tn.C_NEV = '2018/2019'
	INNER JOIN T_INTEZMENY i ON i.ID = oo.C_INTEZMENYID AND i.TOROLT = 'F' AND i.C_FENNTARTOID<900
	INNER JOIN T_OSZTALYCSOPORT ocs ON ocs.ID = oo.C_OSZTALYCSOPORTID AND ocs.TOROLT = 'F'
	LEFT JOIN T_CSOPORT cs ON cs.ID = ocs.ID AND cs.TOROLT = 'F'
	LEFT JOIN T_CSOPORTTIPUS cst ON cst.ID = cs.C_TIPUSA AND cst.C_ALTANEVID = cs.C_ALTANEVID AND cst.TOROLT = 'F'
WHERE oo.C_ORAVEGE = oo.C_ORAKEZDETE AND oo.TOROLT = 'F'

UPDATE tt SET C_ORAVEGE = DATEADD(MINUTE,ISNULL(cst.C_ORAPERC,45),tt.C_ORAVEGE)
FROM T_TANITASIORA tt
	INNER JOIN T_TANEV tn ON tn.ID=tt.C_TANEVID AND tn.TOROLT='F' AND tn.C_NEV='2018/2019'
	INNER JOIN T_INTEZMENY i ON i.ID=tt.C_INTEZMENYID AND i.TOROLT='F' AND i.C_FENNTARTOID<900
	INNER JOIN T_OSZTALYCSOPORT ocs ON ocs.ID=tt.C_OSZTALYCSOPORTID AND ocs.TOROLT='F'
	LEFT JOIN T_CSOPORT cs ON cs.ID=ocs.ID AND cs.TOROLT='F'
	LEFT JOIN T_CSOPORTTIPUS cst ON cst.ID=cs.C_TIPUSA AND cst.C_ALTANEVID=cs.C_ALTANEVID AND cst.TOROLT='F'
WHERE tt.C_ORAVEGE=tt.C_ORAKEZDETE AND tt.TOROLT='F'
