-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
--[C6MartPeriodico].[PL_GetClientSelfNegCurrentAccountValue] 'S','LMNFNC40L14L219U'
CREATE procedure [C6MartPeriodico].[PL_GetClientSelfNegCurrentAccountValue]
	@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;
	--DECLARE @PatrimonioBF DECIMAL(15,2)
     SELECT  	 	 
		 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
	--Return @PatrimonioBF
END