Is there an IF statement that I can use in an Oracle SQL statement.
Example:
SELECT
item,
description,
Week1 = If orderdate between A and B Then qty, else 0
Week2 = If orderdate between C and D then qty, else 0
and so forth...
FROM
orders;
The dcode() function is good only if you have predefined values to check against, it can't help in range comparisions.
What you need is a UNION to join two SQL statements like this:
SELECT item, description, qty as wk_name
FROM orders
where orderdate between A and B
UNION
SELECT item, description, 0 as wk_name
FROM orders
where orderdate not between A and B
;
Well a Union would be nice, but really i am looking to having several columns
7 weeks
and this is a VERY large table, so 7 queries unioned together would be VERY large indeed.
I can't believe there is no logic commands besides strict = in Oracle SQL
You're right, that is probably the only way you can do it, but there are likely to be major performance implicants .......... it could run like a dog :-)
Bookmarks