﻿IF OBJECT_ID('stage.fnGetTanuloAdatok') IS NOT NULL BEGIN
  DROP FUNCTION stage.fnGetTanuloAdatok 
END
GO

CREATE FUNCTION stage.fnGetTanuloAdatok (
  @lastLoad datetime
) RETURNS xml AS 
BEGIN
  DECLARE @xml xml
  SET @xml = (
    SELECT
      i.C_AZONOSITO AS intezmenyAzonosito,
      s.C_TANEVNEV AS tanevNev,  
      s.C_TANULOID AS tanuloId,
      s.C_TANULONEME AS neme,
      s.C_TANULOSZULETESIDATUM AS szuletesiDatum,
      s.C_SAJATOSNEVELESU AS sajatosNevelesu,
      s.C_BTMPROBLEMAS AS btmProblemas,
      s.C_SNILETSZAMSULY AS sniLetszamsuly,
      s.C_BTMLETSZAMSULY AS btmLetszamsuly,
	    s.C_OKTATASIAZONOSITO AS oktatasiAzonosito,
      s.C_EGYEBDONTO AS egyebDonto,
      s.C_EVISMETLO  AS evismetlo,
      s.C_MEGALLAPODASOS AS megallapodasos,
      s.C_OSZTV AS OSZTV,
      s.C_SZETVAGAZAT AS SZETVAgazat,
      s.C_SZINTVIZSGA AS szintvizsga,
      s.C_SZKTV AS SZKTV,
      s.C_TANULOSZERZODESES AS tanuloszerzodeses,
      s.C_TECHNIKUSIEVFOLYAM AS technikusiEvfolyam,
      s.C_FELADATELLATASIHELYID AS feladatellatasiHelyId,
      s.C_NYOMTATASINEV AS nyomtatasiNev,
      s.TOROLT AS torolt
    FROM stage.T_TANULOADATOK_STAGE s
      INNER JOIN dbo.T_INTEZMENY i ON i.ID = s.C_INTEZMENYID
    WHERE s.LASTCHANGED > @lastLoad
    FOR XML RAW ('TanuloAdatok'), ROOT('TanuloAdatokItems')
  );
  RETURN @xml  
END;
GO
