DROP PROCEDURE IF EXISTS uspGetTanuloAdatokEugyintezes
GO
  CREATE PROCEDURE uspGetTanuloAdatokEugyintezes
     @pTanuloOktatasiAzonosito NVARCHAR(20)
    ,@pTanevId INT
  AS
  BEGIN
    SET NOCOUNT ON;

    SELECT DISTINCT Felhasznalo.ID AS KretaAzonosito
      ,Felhasznalo.C_OKTATASIAZONOSITO AS OktatasiAzonosito
      ,ISNULL(Felhasznalo.C_ELOTAG, '') AS Elotag
      ,Felhasznalo.C_VEZETEKNEV AS Vezeteknev
      ,Felhasznalo.C_UTONEV AS KeresztNev
      ,Felhasznalo.C_SZULETESIHELY AS SzuletesiHely
      ,Felhasznalo.C_SZULETESIDATUM AS SzuletesiIdo
      ,Felhasznalo.C_ANYJANEVE AS AnyjaNeve
      ,ISNULL(Cim.C_VAROS, '(N/A)') AS KeltezesHelyseg
      ,OrszagDictionaryItemBase.C_NAME AS Orszag
      ,Cim.C_ORSZAG AS OrszagId
      ,iso.C_ISOKOD AS Isokod
      ,Cim.C_IRANYITOSZAM AS Iranyitoszam
      ,Cim.C_VAROS AS Helyseg
      ,Cim.C_KOZTERULET AS KozteruletNeve
      ,Cim.C_KOZTERULETJELLEGENEV AS KozteruletJellege
      ,Cim.C_HAZSZAM AS Hazszam
      ,Cim.C_EMELET AS Emelet
      ,Cim.C_AJTO AS Ajto
      ,Cim.ID AS CimKretaAzonosito
      ,Felhasznalo.C_EGYEDIAZONOSITO AS EgyediAzonosito
      ,Felhasznalo.C_IDPEGYEDIAZONOSITO AS IdpEgyediAzonosito
    FROM T_FELHASZNALO_OSSZES Felhasznalo
    LEFT JOIN T_CIM_OSSZES Cim ON Cim.C_FELHASZNALOID = Felhasznalo.ID
      AND Cim.C_GONDVISELOID IS NULL
      AND Cim.TOROLT = 'F'
    LEFT JOIN T_DICTIONARYITEMBASE_OSSZES OrszagDictionaryItemBase ON OrszagDictionaryItemBase.ID = Cim.C_ORSZAG
      AND OrszagDictionaryItemBase.TOROLT = 'F'
      AND OrszagDictionaryItemBase.C_INTEZMENYID = Felhasznalo.C_INTEZMENYID
      AND OrszagDictionaryItemBase.C_TANEVID = Felhasznalo.C_TANEVID
    INNER JOIN T_ORSZAGTIPUS_OSSZES iso ON iso.ID = OrszagDictionaryItemBase.ID
      AND iso.C_ALTANEVID = OrszagDictionaryItemBase.C_TANEVID
      AND iso.TOROLT = 'F'
    WHERE Felhasznalo.TOROLT = 'F'
      AND Felhasznalo.C_OKTATASIAZONOSITO = @pTanuloOktatasiAzonosito
      AND Felhasznalo.C_TANEVID = @pTanevId
  END
GO


