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

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Divide by Zero Error

Author  Topic 

skourangi
Starting Member

7 Posts

Posted - 2006-05-16 : 16:13:50
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
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-05-16 : 16:37:21
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
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-05-16 : 16:47:20
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 - 2006-05-17 : 11:47:13
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 - 2006-05-17 : 12:11:25
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
   

- Advertisement -