Conditional Statements in View?
127934Mar 30 2005 — edited Mar 30 2005Is there a way to define a view with an embedded conditional statement? I have a view which calculates a value for a phantom 'Total' field. It works by multiplying Quantity by Unit_Price but a special case has come up where the Unit_Price is the actual value for total and any value for Quantity is to be ignored.
I've tried the following view definition but of course the conditional statement doesn't work. Is this a syntax problem or is it impossible to define a view with an embedded 'if' statement?
DROP VIEW Vendor_Override_test;
CREATE VIEW Vendor_Override_test as
Select VENDOR_TICKET_ITEMS.VendorTicketItemID,
VENDOR_TICKET_ITEMS.Item_Code,
VENDOR_TICKET_ITEMS.Quantity,
VENDOR_ITEMS.Unit_price,
if VENDOR_TICKET_ITEMS.Item_Code = 'OVR'
cast((VENDOR_ITEMS.Unit_price) as number) Total
else
cast((VENDOR_TICKET_ITEMS.Quantity
*VENDOR_ITEMS.Unit_price) as number) Total,
From Vendor_ticket_items, Vendor_Items
Where (VENDOR_ITEMS.Item_code = VENDOR_TICKET_ITEMS.Item_code)
ORDER by item_code;