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 Counter

Author  Topic 

indr4w
Starting Member

27 Posts

Posted - 2013-07-14 : 22:33:07
Hi..all,
How to solve divide by zero error when I need to display
all records in query?
Example:
CodeItem QtyOK Target
A 50 0
B 100 50
C 0 50

The query should resulting records like this :
CodeItem QtyOk Target Percent(QtyOk/Target)
A 50 0 0
B 100 50 200
C 0 50 0

Thank you.

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-07-14 : 22:56:55
Try:
[CODE]
QtyOk / NULLIF(Target,0)
[/CODE]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-07-23 : 05:08:00
or in General

QtyOk / case when Target=0 then NULL else Target end


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -