﻿--Migration
INSERT INTO T_USERPROFILE (
   C_PROFILE
  ,C_FELHASZNALOID
  ,C_INTEZMENYID
  ,C_TANEVID
  ,TOROLT
  ,SERIAL
  ,LASTCHANGED
  ,CREATED
  ,MODIFIER
  ,CREATOR
  ,NNID
  ,ELOZOTANEVIREKORDID
  ,C_ISPOPUPMEGJELENITES
) SELECT
   N'<UserProfile><Menu></Menu></UserProfile>' AS C_PROFILE
  ,fh.ID AS C_FELHASZNALOID
  ,fh.C_INTEZMENYID AS C_INTEZMENYID
  ,fh.C_TANEVID AS C_TANEVID
  ,'F' AS TOROLT
  ,0 AS SERIAL
  ,GETDATE() AS LASTCHANGED
  ,GETDATE() AS CREATED
  ,NULL AS MODIFIER
  ,NULL AS CREATOR
  ,NULL AS NNID
  ,NULL AS ELOZOTANEVIREKORDID
  ,'F' AS C_ISPOPUPMEGJELENITES
FROM T_FELHASZNALO fh
  INNER JOIN T_TANEV tv ON tv.ID = fh.C_TANEVID AND tv.C_AKTIV = 'T' AND tv.TOROLT = 'F'
  INNER JOIN T_INTEZMENY i ON i.ID = tv.C_INTEZMENYID AND i.TOROLT = 'F'
WHERE NOT EXISTS (SELECT 1 FROM T_USERPROFILE up WHERE up.C_FELHASZNALOID = fh.ID)