Avoid Divide by Zero Errors

,

A simple User Function which will guarantee always to return a value from a division without any errors

Example : GPDivNErr(@Val1 float, @Val2 float)

CREATE FUNCTION GPDivNErr(@Val1 float, @Val2 float)
RETURNS float
AS  
BEGIN 

	DECLARE @MyVal FLOAT
	IF @Val2=0
		SELECT @MyVal = 0
	ELSE
		SELECT @MyVal = @Val1/@Val2
	RETURN @MyVal
END

Rate

Share

Share

Rate