Technical Article

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

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating