﻿SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF OBJECT_ID('[dbo].[sp_GetFotargyakhozTartozoAltargyak]') IS NOT NULL
BEGIN
	DROP PROCEDURE [dbo].[sp_GetFotargyakhozTartozoAltargyak]
END
GO

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

	-- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements.
	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 fotargy.TOROLT = ''F''';


EXEC sp_executesql @command



END


GO

