DROP PROCEDURE IF EXISTS [dbo].[sp_GetFotargyakhozTartozoAltargyak]
GO

CREATE PROCEDURE [dbo].[sp_GetFotargyakhozTartozoAltargyak]
   @pFotargyIdList    nvarchar(max)   
AS
BEGIN

  SET NOCOUNT ON;

DECLARE @command nvarchar(max)

SET @command = '
  SELECT 
     fotargy.C_NEV fotargyNev
    ,altargy.C_NEV altargyNev
  FROM 
    T_TANTARGY_OSSZES fotargy
    INNER JOIN 
    T_TANTARGY_OSSZES altargy ON altargy.C_FOTARGYID = fotargy.ID
  WHERE   
    fotargy.ID IN ('+ @pFotargyIdList + ')  
    AND fotargy.C_FOTARGYE = ''T''
    AND altargy.C_FOTARGYE = ''F''
    AND altargy.TOROLT = ''F''';

EXEC sp_executesql @command

END

GO

