/* Formatted on 08-Apr-12 5:27:39 PM (QP5 v5.115.810.9015) */
/*HOW TO FIND THE ON HAND QUANTITY FOR A SPECIFIC DATE */
SELECT ITEM_ID, SUM (TARGET_QTY) quantity
FROM ( SELECT moqd.inventory_item_id item_id,
SUM (primary_transaction_quantity) target_qty
FROM mtl_onhand_quantities_detail moqd
WHERE moqd.organization_id = :p_organizations
-- and moqd.inventory_item_id =65345
AND moqd.owning_tp_type =
DECODE (2, 2, 2, moqd.owning_tp_type)
GROUP BY moqd.inventory_item_id
UNION
SELECT mmt.inventory_item_id item_id,
-SUM (primary_quantity) target_qty
FROM mtl_material_transactions mmt,
mtl_txn_source_types mtst,
mtl_parameters mp
WHERE mmt.organization_id = :p_organizations
AND mp.organization_id = :p_organizations
AND trunc(transaction_date) >= to_date((:p_start_date ),'DD-MON-RR')+ 1
AND NVL (mmt.owning_tp_type, 2) =
DECODE (2, 2, 2, NVL (mmt.owning_tp_type, 2))
AND mmt.transaction_source_type_id =
mtst.transaction_source_type_id
AND NVL (mmt.logical_transaction, 2) <> 1
-- and mmt.inventory_item_id =65345
GROUP BY mmt.inventory_item_id)
GROUP BY ITEM_ID
No comments:
Post a Comment