May 19th, 2011, 12:33 PM
Join Date: May 2011
Time spent in forums: 1 h 26 m 54 sec
Reputation Power: 0
Complex Case Expression
Hello, I'm really new to writing SQL queries to query Oracle databases and could use a little assistance. I hope I'm in the correct forum.
I have a case expression as follows:
(CASE WHEN DATEa=DATEb THEN 0
WHEN DATEa> DATEb THEN NETWORKDAYS(DATEb, DATEa)
WHEN DATEa < DATEb THEN NETWORKDAYS(DATEa, DATEb)
WHEN STATUS='PENDING' THEN NULL
END) AS RESULTa,
Now what I need to be able to do is place those results in buckets, similar to this:
(CASE WHEN RESULTa < 0 THEN '<0'
WHEN RESULTa between -1 AND 6 THEN '<=5'
WHEN RESULTa >5 THEN '>5'
END) AS BUCKETa
I understand that I can't call an alias from a previous case expresson to get these desired results and I'm confused on how I could combine the two statements to get the desired bucket.
Any assistance or advice anyone could provide would be most appreciated.