-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE    FUNCTION [C6StagingPeriodico].[getTermID]
(
	-- Add the parameters for the function here
	@Rete varchar(2),
	@Codice_fiscale varchar(16)
)
RETURNS VARCHAR(255)
AS
BEGIN
	-- Declare the return variable here
	DECLARE @ValoreParametro decimal(15,2)
	SELECT	@ValoreParametro=isnull(SUM(ctv),0.00) 
	from C6MartPeriodico.PATRIMONIO_BF  where substring(patrimonio_bf.position_id,97,8)in('BDR20000','TDV20000') --BDR2000 Cash Deposit TDV20000 TimeDeposit
	and	RETE=@Rete and Cod_Fiscale=@Codice_fiscale
	-- Return the result of the function
	RETURN @ValoreParametro
END