|
swenri
Yak Posting Veteran
72 Posts |
Posted - 2009-04-06 : 18:03:46
|
| I’ve a question. I’m trying to execute a union query in Oracle10g (linked tables to Sql Server 2005). I was able to run the query but, in the resultset it is not showing the Total_Cost which is located in the second select query. The only difference in the 2 queries is the Total Price and Total_Cost rest of the columns are all same. Isn’t it true that only the datatype should match for a union query and not the column names? I tried UNION operator also yet, I get the same result.Can anybody let me know what's wrong ? Here is the query that I ran *********************************************************************************SELECT ORDERS.ORDER_ID, ORDERS.ORDER_DTM, ORDERS.ORDER_COMPLETION_TIME, Sum(Decode(PRICE.ACTUAL_PRICE,0,'0',PRICE.ACTUAL_PRICE)) AS TOTAL_PRICE, Decode(ORDERS.CANCELLED_IND, 1,'Yes',null) AS Cancelled, CONTACT.COMPANY, ACCOUNT.EXTERNAL_ACCOUNT_NUMBER, SERVICE.SERVICE_NM AS Service, ORDERS.EXPORTED_DTMFROM ORDERS, ORDER_STATE, ACCOUNT, CONTACT, SERVICE, PRICEWHERE PRICE.ORDER_ID = ORDERS.ORDER_IDAND PRICE.DELETED_IND = 0AND ORDERS.ACCOUNT_ID = ACCOUNT.ACCOUNT_IDAND ACCOUNT.CONTACT_ID = CONTACT.CONTACT_IDAND ORDERS.SERVICE_ID = SERVICE.SERVICE_IDAND ORDERS.ORDER_DTM > trunc(sysdate) - 150AND ORDERS.EXPORTED_DTM Is NullAND ORDERS.ORDER_STATE_CD <>'OC' AND ORDERS.ORDER_STATE_CD <>'CNC'GROUP BY ORDERS.ORDER_ID, ORDERS.ORDER_DTM, ORDERS.ORDER_COMPLETION_TIME, Decode(ORDERS.CANCELLED_IND, 1,'Yes',null), ORDERS.EXPORTED_DTM, CONTACT.COMPANY, ACCOUNT.EXTERNAL_ACCOUNT_NUMBER, SERVICE.SERVICE_NM, ORDERS.EXPORTED_DTM UNION ALL SELECT ORDERS.ORDER_ID, ORDERS.ORDER_DTM, ORDERS.ORDER_COMPLETION_TIME, Sum(Decode(VENDOR_COST.ACTUAL_COST,0,'0',VENDOR_COST.ACTUAL_COST)) AS TOTAL_COST, Decode(ORDERS.CANCELLED_IND, 1,'Yes',null) AS Cancelled, CONTACT.COMPANY, ACCOUNT.EXTERNAL_ACCOUNT_NUMBER, SERVICE.SERVICE_NM AS Service, ORDERS.EXPORTED_DTMFROM ORDERS, ORDER_STATE, ACCOUNT, CONTACT, SERVICE, VENDOR_COSTWHERE VENDOR_COST.ORDER_ID = ORDERS.ORDER_IDAND VENDOR_COST.DELETED_IND = 0AND ORDERS.ACCOUNT_ID = ACCOUNT.ACCOUNT_IDAND ACCOUNT.CONTACT_ID = CONTACT.CONTACT_IDAND ORDERS.SERVICE_ID = SERVICE.SERVICE_IDAND ORDERS.ORDER_DTM > trunc(sysdate) - 150AND ORDERS.EXPORTED_DTM Is NullAND ORDERS.ORDER_STATE_CD <>'OC' AND ORDERS.ORDER_STATE_CD <>'CNC'GROUP BY ORDERS.ORDER_ID, ORDERS.ORDER_DTM, ORDERS.ORDER_COMPLETION_TIME, Decode(ORDERS.CANCELLED_IND, 1,'Yes',null), ORDERS.EXPORTED_DTM, CONTACT.COMPANY, ACCOUNT.EXTERNAL_ACCOUNT_NUMBER, SERVICE.SERVICE_NM, ORDERS.EXPORTED_DTM |
|