DROP PROCEDURE IF EXISTS uspGetAdatszotar
GO

CREATE PROCEDURE uspGetAdatszotar
   @pTanevId int
  ,@pTypeId int
AS BEGIN
  SET NOCOUNT ON;

  DECLARE @sql nvarchar(1000)

  SET @sql = N'
    SELECT
       dib.ID AS ID
      ,dib.C_ORDER AS Sorszam
      ,dib.C_NAME AS Megnevezes
      ,dib.C_NAME_1 AS Megnevezes1
      ,dib.C_NAME_2 AS Megnevezes2
      ,dib.C_NAME_3 AS Megnevezes3
      ,dib.C_NAME_4 AS Megnevezes4
      ,dib.C_TYPE AS AdatszotarTipus
      ,dib.C_DICTIONARYTYPEID AS AdatszotarTipusId
      ,dib.C_VISIBLE AS Lathato
      ,dib.C_PROTECTED AS Protected
      ,ISNULL(nt.C_ISSORSZAMOZANDO,''F'') AS IsSorszamozando
      ,ISNULL(nt.C_ISTANORAI,''F'') AS IsTanorai
      ,ISNULL(nt.C_ISTANORANKIVULI,''F'') AS IsTanorankivuli
      ,ISNULL(nt.C_ISLENEMKOTOTTMUNKAIDO,''F'') AS IsLeNemKotottMunkaido
    FROM T_DICTIONARYITEMBASE_OSSZES dib
      LEFT JOIN T_NAPTIPUS nt ON nt.ID = dib.ID AND nt.C_ALTANEVID = dib.C_TANEVID AND nt.TOROLT = ''F'' 
    WHERE dib.C_DICTIONARYTYPEID = @pTypeId
      AND dib.C_TANEVID = @pTanevId
      AND dib.TOROLT = ''F'''

  EXEC sys.Sp_executesql @sql, N'
     @pTanevId int
    ,@pTypeId int'
    ,@pTanevId
    ,@pTypeId 

END

GO
