﻿UPDATE
    tcs
SET
    tcs.C_KILEPESDATUM = '20170831 23:59:00'
FROM
    T_TANULOCSOPORT tcs
INNER JOIN
    T_TANEV tanev ON tanev.C_INTEZMENYID = tcs.C_INTEZMENYID AND tanev.ID = tcs.C_TANEVID
WHERE
        tcs.TOROLT = 'F'
    AND tanev.TOROLT = 'F'
    AND tcs.C_KILEPESDATUM = tanev.C_UTOLSOTANITASINAP
    AND tcs.LASTCHANGED > DATEADD(week,-3,GETDATE())
