Company: Link Technologies
Case No: L12389
Logged By: Sanjay (Link Technologies) on 28 Aug 2011 09:04PM
Priority: Not Applicable
Product: Other
Group: To be assigned
Time Taken: 0.00
Assigned To: Sanjay (Link Technologies)
Circulation: Sanjay
Resolve By: Sunday, 28 August 2011 09:04 PM [4626 days since logged date]
Status: Closed
Subject: SQL Server - Division by zero
Summary:    
Here is an easy way to use NULLIF function to handle division by zero error.

NULLIF - Returns a null value if the two specified expressions are equal.

For example:

DECLARE @a INT
DECLARE @div INT

SET @a = 10
SET @div = 0

SELECT ISNULL(@a / NULLIF(@div,0),@a) -- Returns @a when @div = 0
SELECT ISNULL(@a / NULLIF(@div,0),0) -- Returns 0 when @div = 0
Audit Notes:
If you have any queries regarding this support incident, please email admin@linktechnologies.com.au and include the Case No: L12389 in the subject line of all emails regarding this issue.

Document size: 0.9 KB
For call complaints, please contact the Managing Director of the company using this form