SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

skourangi
Starting Member

7 Posts

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

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!

Srinika
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>

Srinika
Go to Top of Page

Seventhnight
Flowing Fount of Yak Knowledge

USA
2878 Posts

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

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

Corey

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

skourangi
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

sshelper
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:

http://www.sql-server-helper.com/error-messages/msg-8134.aspx

SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000