Social Icons

Wednesday, July 31, 2013

Sales order returns details query in R12


SELECT   a.sold_to customer_name, c.account_number, a.order_number,
         (SELECT order_number
            FROM oe_order_headers_all
           WHERE header_id = b.reference_header_id) reference_order_no,
         (SELECT cust_po_number
            FROM oe_order_headers_all
           WHERE header_id = b.reference_header_id) reference_po_no,
         a.cust_po_number return_po_number,
         TO_CHAR (a.ordered_date, 'DD-MON-YYYY') order_date,
         SUM (ordered_quantity * unit_list_price) return_sales_order_value,
         (SELECT SUM (ordered_quantity * unit_list_price
                     )
            FROM oe_order_headers_all ooh, oe_order_lines_all ool
           WHERE ooh.header_id = ool.header_id
             AND ooh.header_id = b.reference_header_id)
                                                  reference_sales_order_value
    FROM oe_order_headers_v a, oe_order_lines_v b, hz_cust_accounts_all c
   WHERE a.header_id = b.header_id
     AND a.sold_to_org_id = c.cust_account_id
     AND a.order_type LIKE '%RETURN%'
     AND TO_CHAR (a.creation_date, 'MON-YYYY') = 'JUL-2013'
GROUP BY a.sold_to,
         c.account_number,
         a.order_number,
         a.ordered_date,
         a.cust_po_number,
         b.reference_header_id
ORDER BY 5, 3

1 comment :

">