Monday, 13 May 2013

Query to find Expected Lines in rcv shipment


/* Formatted on 5/11/2013 7:53:40 PM (QP5 v5.115.810.9015) */
SELECT   (SELECT   (SELECT   name
                      FROM   hr_operating_units
                     WHERE   organization_id = org_id)
            FROM   po_headers_all
           WHERE   po_header_id = rsl.po_header_id)
            org_name,
         pv.vendor_name,
         vendor_site_code country,
         rsh.shipment_num,
         (SELECT   segment1
            FROM   po_headers_all
           WHERE   po_header_id = rsl.po_header_id)
            po_number,
         (SELECT   line_num
            FROM   po_lines_all
           WHERE   po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id)
            po_line_num,
         (SELECT   release_num
            FROM   po_releases_all
           WHERE   po_header_id = rsl.po_header_id
                   AND po_release_id = rsl.po_release_id)
            PO_release_num,
         (SELECT   SHIPMENT_NUM
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            PO_RELEASE_LINE_NO,
         rsl.LINE_NUM asn_line_no,
         (SELECT   segment1
            FROM   mtl_system_items_b
           WHERE   inventory_item_id = rsl.item_id AND organization_id = 86)
            part_number,
         (SELECT   QUANTITY
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty,
         (SELECT   QUANTITY_ACCEPTED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_accepted,
         (SELECT   QUANTITY_RECEIVED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_received,
         (SELECT   QUANTITY_BILLED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_billed,
         (SELECT   QUANTITY_CANCELLED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_cancelled,
         QUANTITY_SHIPPED RCV_QUANTITY_SHIPPED,
         QUANTITY_received RCV_QUANTITY_received,
         rsl.shipment_line_status_code,
         (SELECT   CLOSED_CODE
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            PO_CLOSED_STATUS_CODE                                          --,
  FROM   rcv_shipment_headers rsh,
         rcv_shipment_lines rsl,
         po_vendors pv,
         po_vendor_sites_all pvs
 WHERE       1 = 1
         AND rsh.shipment_header_id = rsl.shipment_header_id
         AND rsh.vendor_id = pv.vendor_id
         AND rsh.VENDOR_SITE_ID = pvs.VENDOR_SITE_ID
         AND pv.vendor_id = pvs.vendor_id
         AND rsl.source_document_code = 'PO'
         AND rsl.shipment_line_status_code = 'EXPECTED'
--           AND rsl.po_header_id = 1321
--         AND rsh.shipment_num = 'EAAA42670'

No comments:

Post a Comment