dbTalk Databases Forums  

Division by zero problem

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Division by zero problem in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
cobolman
 
Posts: n/a

Default Division by zero problem - 11-15-2007 , 07:18 AM






I've got the following SQL

SELECT count(*) FROM tablea A
JOIN tableb B ON ..etc..
WHERE a.string_val = 'test' AND
b.divider > 0 AND
a.number > 0 AND
(a.number / b.divider > 0)

The b.divider value can be 0, but still I get the division by zero
error message.
I guess the reason is that the database performs the where statements
one at the time?

So when performing the division a.number / b.divider it could get 0 in
the divider even if b.divider > 0 is also part of the where
statement??

My question is then.. How can I work around this problem? Changing the
database to set b.divider always > 0 is not an option

Reply With Quote
  #2  
Old   
Mark
 
Posts: n/a

Default Re: Division by zero problem - 11-15-2007 , 07:27 AM






Maybe this?

SELECT count(*) FROM tablea A
JOIN tableb B ON ..etc..
WHERE a.string_val = 'test' AND
b.divider > 0 AND
a.number > 0 AND
(a.number / NULLIF(b.divider,0) > 0)

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.