﻿UPDATE mhKov SET
   C_TELEPHELYANYAINTEZMENYID = anya.ID
  ,MODIFIER = 0
  ,LASTCHANGED = GETDATE()
FROM T_MUKODESIHELY mhKov
  INNER JOIN T_TANEV tnKov on tnKov.TOROLT='F' AND tnKov.ID=mhKov.C_TANEVID AND tnKov.C_NEV = '2020/2021'
  INNER JOIN T_MUKODESIHELY anya ON anya.ELOZOTANEVIREKORDID = mhKov.C_TELEPHELYANYAINTEZMENYID AND anya.TOROLT='F' AND anya.C_TANEVID = tnKov.ID
WHERE mhKov.C_TELEPHELYANYAINTEZMENYID IS NOT NULL AND mhKov.TOROLT='F'