-- Schema: C6MartPeriodico
-- Stored Procedure: PL_GetClientSelfNegative




-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
--[C6MartPeriodico].[PL_GetClientSelfNegative] 'S','LMNFNC40L14L219U'
CREATE procedure [C6MartPeriodico].[PL_GetClientSelfNegative]
	@Rete char(1), 
	@CodiceFiscale varchar(16)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT  	 	 
		CodInterno,
		case
		when CodInterno = 'XY' then '"Linee GP Eligo"'
		when CodInterno = 'FO' then '"IL MF - Liquidita"'
		end as Descrizione,
		cast( case when isnull(SUM(CTV),0) = 0 then 0 else SUM(CTV) end as decimal(15,2)) as CTV
	FROM       
		C6MartPeriodico.ANAG_SELF LS	
	WHERE 
		LS.rete = @Rete
		AND LS.codfis = @CodiceFiscale
		AND ctv < 0
	group by CodInterno
END
 
   


