Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Divide by Zero Error
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

7 Posts

Posted - 05/16/2006 :  16:13:50  Show Profile  Reply with Quote

I get a divide by zero error message in SQL Server 2000 in my query.
Does anyone know what is the best way to handle it?

Thank you!

Flowing Fount of Yak Knowledge

Sri Lanka
1378 Posts

Posted - 05/16/2006 :  16:37:21  Show Profile  Reply with Quote
Let the query be executed when the Deviding field(s) are not zero

Select F1/(DF1 * DF2) from Urtbl where DF1 <> 0 and DF2 <> 0 and <ur other conditions>

Go to Top of Page

Flowing Fount of Yak Knowledge

2878 Posts

Posted - 05/16/2006 :  16:47:20  Show Profile  Visit Seventhnight's Homepage  Reply with Quote

Select case when DF1<>0 and DF2 <> 0 then F1/(DF1 * DF2) else <SomeDefaultValue> end from Urtbl where <ur other conditions>


Co-worker on children "...when I have children, I'm going to beat them. Not because their bad, but becuase I think it would be fun ..."
Go to Top of Page

Starting Member

7 Posts

Posted - 05/17/2006 :  11:47:13  Show Profile  Reply with Quote
Thanks for your reponse.

I used the Nullif function which worked because I had a very
long subquery that I didn't want to make longer.
Go to Top of Page

Posting Yak Master

216 Posts

Posted - 05/17/2006 :  12:11:25  Show Profile  Visit sshelper's Homepage  Reply with Quote
There are 3 ways to avoid the division by zero error and all three are discussed in the following link:

SQL Server Helper
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000