﻿--Migration
INSERT INTO T_TANULOHAZIFELADATSTATUSZ (
   C_ISMEGOLDVA
  ,C_MEGOLDASIDEJE
  ,C_TANULOID
  ,C_HAZIFELADATOKID
  ,C_INTEZMENYID
  ,C_TANEVID
  ,TOROLT
  ,SERIAL
  ,LASTCHANGED
  ,CREATED
  ,MODIFIER
  ,CREATOR
  ,ELOZOTANEVIREKORDID
) SELECT
   'F' AS C_ISMEGOLDVA -- * char(1)
  ,NULL AS C_MEGOLDASIDEJE -- datetime
  ,tcs.C_TANULOID AS C_TANULOID -- * int
  ,hf.ID AS C_HAZIFELADATOKID -- * int
  ,hf.C_INTEZMENYID AS C_INTEZMENYID -- * int
  ,hf.C_TANEVID AS C_TANEVID -- * int
  ,'F' AS TOROLT -- * char(1)
  ,0 AS SERIAL -- * int
  ,GETDATE() AS LASTCHANGED -- * datetime
  ,GETDATE() AS CREATED -- * datetime
  ,NULL AS MODIFIER -- int
  ,NULL AS CREATOR -- int
  ,NULL AS ELOZOTANEVIREKORDID -- int
FROM T_TANULOCSOPORT tcs
  INNER JOIN T_HAZIFELADATOK hf ON hf.C_FELADASDATUMA >= tcs.C_BELEPESDATUM AND hf.TOROLT = 'F'
    AND hf.C_FELADASDATUMA < ISNULL(tcs.C_KILEPESDATUM, '22000101')
    AND tcs.C_TANEVID = hf.C_TANEVID
    AND hf.C_OSZTALYCSOPORTID = tcs.C_OSZTALYCSOPORTID
  INNER JOIN T_TANEV tv ON tv.ID = tcs.C_TANEVID AND tv.C_NEV = '2019/2020' AND tv.C_AKTIV = 'T'
WHERE tcs.TOROLT = 'F'
ORDER BY hf.ID    
