IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'dbo.CF_Cbte_Rec_Total_Pago') 
                   and type = 'FN')
BEGIN
    DROP FUNCTION dbo.CF_Cbte_Rec_Total_Pago
END
GO

CREATE FUNCTION dbo.CF_Cbte_Rec_Total_Pago (@pId_Trans  INT)
RETURNS DECIMAL(16,2)
AS
BEGIN
DECLARE @Pagado DECIMAL(16,2)

SELECT @Pagado =SUM(V.Importe) 
	FROM Valores_Mov M, Valores V  
	WHERE V.Id_Valor = M.Id_Valor
	AND M.Renglon_Nro = 1
	AND M.id_trans = @pId_Trans



RETURN @Pagado
END

