I have a table, e.g. ORDERS, each order has a receipt, but the receipts are separated in 3 tables. RECEIPT1, RECEIPT2 and RECEIPT3.
A column on table ORDERS called ORDER_TYPE will define in which of the RECEIPT tables the receipt is.
On my query I need a logic that does something like this: If ORDER_TYPE = 'C' my query gets a value from RECEIPT1, if it's equals 'X' from RECEIPT2 and etc.
I've already tried to use a left join on the 3 tables, but it returns triplicated rows and even if I group all of them there's still a chance of error.
Can anyone help me? Maybe cursors (which I dont know very much how to use)?
[RECEIPTn]should probably be[RECEIPT]with anncolumn