Link to home
Start Free TrialLog in
Avatar of ehart12
ehart12Flag for United States of America

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!


ASKER CERTIFIED SOLUTION
Avatar of ViaTom
ViaTom
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ehart12

ASKER

Hi ViaTom,

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


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.
Avatar of ehart12

ASKER

Oh ya, I see what you mean!  Thank you very much...
Avatar of ehart12

ASKER

awesome!
welcome, and thanks for the points.