/****** Object:  UserDefinedFunction [dbo].[UFD_EST_PED_CP_IT_SLD]    Script Date: 22/10/2014 09:52:09 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UFD_EST_PED_CP_IT_SLD]') 
			AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[UFD_EST_PED_CP_IT_SLD]
GO
GO

--SELECT DBO.UFD_EST_PED_CP_IT_SLD(1,16,1538, 1)
CREATE FUNCTION [dbo].[UFD_EST_PED_CP_IT_SLD](
												  @CD_EMP		INT,
												  @CD_FILIAL 	INT,
												  @CD_PED		INT,
												  @CD_PROD     INT)
RETURNS MONEY
AS
BEGIN

	DECLARE	@QT_IT_SLD_FINAL MONEY
 
	SELECT @QT_IT_SLD_FINAL = [dbo].[UFD_EST_PED_CP_IT_SLD_DANFE] (@CD_EMP, @CD_FILIAL, @CD_PED, @CD_PROD, 0, 0)

	IF @QT_IT_SLD_FINAL < 0
	BEGIN
		SET @QT_IT_SLD_FINAL=0
	END

	RETURN(@QT_IT_SLD_FINAL)
END


