IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PLANTA_CALC_PRORESS]') 
	AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[PLANTA_CALC_PRORESS]
GO
CREATE FUNCTION PLANTA_CALC_PRORESS(@TOTAL_COSTS float, @COSTS_ACT float) 
RETURNS float
BEGIN
	DECLARE @returnvalue float;

    SET @returnvalue = 
		CASE
			WHEN COALESCE(@TOTAL_COSTS,0) = 0 or COALESCE(@COSTS_ACT,0) = 0 THEN 0
			WHEN @COSTS_ACT / @TOTAL_COSTS > 0 THEN @COSTS_ACT / @TOTAL_COSTS
			ELSE 0
		END
    RETURN @returnvalue;
END;
GO
