ehart12
asked on
SQL Math (newbie)
Hi Experts,
I am attempting to write a Oracle statement that takes two existing database objects and performs some simple math to create dynamic variable.
select
wdj.attribute14,
wdj.attribute15,
decode(wdj.attribute14 / wdj.attribute15, 0, 0) cpr
from wip.wip_discrete_jobs wdj
I have been playing with the above code and cannot seem to figure it out.
I would like to divide ATTRIBUTE14 and ATTRIBUTE15 and name the new column CPR...
Thank you!
I am attempting to write a Oracle statement that takes two existing database objects and performs some simple math to create dynamic variable.
select
wdj.attribute14,
wdj.attribute15,
decode(wdj.attribute14 / wdj.attribute15, 0, 0) cpr
from wip.wip_discrete_jobs wdj
I have been playing with the above code and cannot seem to figure it out.
I would like to divide ATTRIBUTE14 and ATTRIBUTE15 and name the new column CPR...
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hi eric,
if the numerator (the first variable in a division operation, in this case attribute14) is zero, the function will return zero. you only need the case for attribute15 = 0 to avoid a divide-by-zero error.
if the numerator (the first variable in a division operation, in this case attribute14) is zero, the function will return zero. you only need the case for attribute15 = 0 to avoid a divide-by-zero error.
ASKER
Oh ya, I see what you mean! Thank you very much...
ASKER
awesome!
welcome, and thanks for the points.
ASKER
Thank you very much for the CASE example. Since both ATTRUBITE14 and ATTRIBUTE15 could be ZERO, how would you add another "when wdj.attribute14 = 0 then 0" to the statement?
Thanks again,
Eric