-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
--[C6Mart].[PL_GetClientSelfNegative] 'S','LMNFNC40L14L219U'
CREATE procedure [C6Mart].[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       
		C6Mart.ANAG_SELF LS	
	WHERE 
		LS.rete = @Rete
		AND LS.codfis = @CodiceFiscale
		AND ctv < 0
	group by CodInterno
END