Tuesday, 1 November 2011

ITEM_LAST_PO_QRY

SELECT   p.unit_price,
         P.LIST_PRICE_PER_UNIT,
         (SELECT   PRIMARY_UNIT_OF_MEASURE
            FROM   mtl_system_items_b
           WHERE       inventory_item_id = p.item_id
                   AND SUBSTR (SEGMENT1, 1, 1) = :P_ITEM_CODE
                   AND organization_id = 1206)
            UOM,     
         b.item_id,
         (SELECT   segment1
            FROM   mtl_system_items_b
           WHERE       inventory_item_id = p.item_id
                   AND SUBSTR (SEGMENT1, 1, 1) = :P_ITEM_CODE
                   AND organization_id = 1206)
            item_code,
           b.po_date
  FROM   po_lines_all p,
         (  SELECT   item_id, MAX (creation_date) po_date
              FROM   po_lines_All
             WHERE   item_id IN
                           (SELECT   inventory_item_id
                              FROM   mtl_system_items_b msi
                             WHERE   SUBSTR (MSI.SEGMENT1, 1, 2) = :P_ITEM_CODE
                                     AND organization_id = 1206)
                     AND TRUNC (Creation_date) <= '31-MAR-2011'
          GROUP BY   item_id) b
 WHERE   p.item_id = b.item_id AND p.creation_date = b.po_date
 order by b.item_id

No comments:

Post a Comment