Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternative for null divisor in calculation

Status
Not open for further replies.

posiedon

Programmer
Mar 22, 2002
8
0
0
GB
Hi

i am using oracle 8.1.7.2 and need to have an alternative within a select statement.

I am calculating the percentage failure from some data
(failure/attempts) * 100

there is the potential for the attempts to = 0, so this will potentially produce an error in the select statement.

how do i say:
if attempts = 0, then the percentage is 0??

thanks

Stephen
 
Depending on how you're doing it, you could use the case statement (if Oracle supports it!) ... something like

select percentage = case attempts
when 0 then 0
else (failure/attempts) * 100
end
from tablename

Greg.
 
Oracle supports CASE as follows:

select failure,
attempts,
(case when attempts = 0
then 0
else (failure/attempts)*100 end)pct
from table1
...


AA :~)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top