﻿--Migration
INSERT INTO T_KEPESITES (
   C_KEPESITESTIPUSID
  ,C_INTEZMENYID
  ,C_TANEVID
  ,TOROLT
  ,SERIAL
  ,LASTCHANGED
  ,CREATED
  ,MODIFIER
  ,CREATOR
  ,ELOZOTANEVIREKORDID
  ,NNID
) SELECT 
   sz.ID AS C_KEPESITESTIPUSID     -- C_KEPESITESTIPUSID - int
  ,sz.C_ALINTEZMENYID   AS C_INTEZMENYID           -- C_INTEZMENYID - int
  ,sz.C_ALTANEVID   AS C_TANEVID               -- C_TANEVID - int
  ,'F'  AS TOROLT                  -- TOROLT - char(1)
  ,0   AS SERIAL                  -- SERIAL - int
  ,GETDATE() AS LASTCHANGED       -- LASTCHANGED - datetime
  ,GETDATE() AS CREATED           -- CREATED - datetime
  ,sz.MODIFIER AS MODIFIER               -- MODIFIER - int
  ,sz.CREATOR AS CREATOR                -- CREATOR - int
  ,NULL AS ELOZOTANEVIREKORDID    -- ELOZOTANEVIREKORDID - int
  ,NULL AS NNID                   -- NNID - int
FROM T_SZAKTIPUS sz
WHERE NOT EXISTS (
  SELECT 1 FROM T_KEPESITES k 
  WHERE k.C_KEPESITESTIPUSID = sz.ID 
    AND k.C_INTEZMENYID = sz.C_ALINTEZMENYID 
    AND k.C_TANEVID = sz.C_ALTANEVID
  );
GO
