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!

Division By 0 error in computed select

Status
Not open for further replies.

andremc

Programmer
Aug 1, 2003
5
0
0
US
How is division by 0 handeled in a computed select statement. I have tried a case stmt. without luck.

Here is an example of what I'm trying to accomplish:
SELECT
d.first_name,
d.last_name,
r.Store_Id,
r.LMLY,
r.Gallons_1mo,
--(r.Gallons_1mo / r.LMLY)-1 as MOM_Change_Per
FROM .....

Thanks a million if anyone has a suggestion!
andremc
 
You sad use use case statement without luck.
Was similar to this ? ( because this may work )

SELECT
d.first_name,
d.last_name,
r.Store_Id,
r.LMLY,
r.Gallons_1mo,
CASE WHEN r.LMLY = 0 TNEN 0
ELSE (r.Gallons_1mo / r.LMLY)-1
END as MOM_Change_Per
FROM .....

Zhavic

---------------------------------------------------------------
In the 1960s you needed the power of two Comodore64s to get a rocket to the moon. Now you need a machine which is a vast number of times more powerful just to run the most popular GUI.
 
Zhavic,

My syntax was a bit off. This works great...thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top