0% found this document useful (0 votes)
135 views5 pages

MTL Aging Query

This document contains SQL queries that are selecting and aggregating data from various Oracle application tables to determine inventory quantities and serial numbers. The tables included are mtl_onhand_qty_cost_v, mtl_material_transactions, mtl_txn_source_types, and mtl_serial_numbers. Joins and where clauses are using columns like organization_id, inventory_item_id, and transaction dates to filter the data. Aggregate functions like SUM are calculating total quantities. The overall goal seems to be reporting on inventory balances and serial numbers as of a given date.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views5 pages

MTL Aging Query

This document contains SQL queries that are selecting and aggregating data from various Oracle application tables to determine inventory quantities and serial numbers. The tables included are mtl_onhand_qty_cost_v, mtl_material_transactions, mtl_txn_source_types, and mtl_serial_numbers. Joins and where clauses are using columns like organization_id, inventory_item_id, and transaction dates to filter the data. Aggregate functions like SUM are calculating total quantities. The overall goal seems to be reporting on inventory balances and serial numbers as of a given date.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

SELECT

moqv.subinventory_code subinv
, moqv.inventory_item_id item_id
, SUM (transaction_quantity) target_qty
,s.serial_number
FROM
mtl_onhand_qty_cost_v moqv
,mtl_system_items_b msi
,mtl_serial_numbers s
WHERE
moqv.organization_id = 99
-- AND
moqv.inventory_item_id = :item_id
AND
moqv.inventory_item_id = msi.inventory_item_id
AND
moqv.organization_id = msi.organization_id
AND
moqv.inventory_item_id = s.inventory_item_id
AND
moqv.organization_id = s.current_organization_id
and
moqv.CREATE_TRANSACTION_ID=s.last_transaction_id
AND
msi.segment1
='HEF02NH016'
GROUP BY moqv.subinventory_code
, moqv.inventory_item_id
, moqv.item_cost
, s.serial_number
UNION
SELECT mmt.subinventory_code subinv
, mmt.inventory_item_id item_id
, -SUM (primary_quantity) target_qty
,s1.serial_number
FROM
mtl_material_transactions mmt
, mtl_txn_source_types mtst
, mtl_system_items_b msi1
,mtl_serial_numbers s1
WHERE
mmt.organization_id = 99
AND
transaction_date >= TO_DATE ('31-dec-2013') + 1
AND
mmt.transaction_source_type_id = mtst.transaction_source_type

_id
--AND
AND
AND
AND
AND
AND
and
GROUP BY
,

mmt.inventory_item_id = :item_id
msi1.segment1
='HEF02NH016'
mmt.inventory_item_id = msi1.inventory_item_id
mmt.organization_id = msi1.organization_id
mmt.inventory_item_id = s1.inventory_item_id
mmt.organization_id = s1.current_organization_id
mmt.transaction_id
=s1.last_transaction_id
mmt.subinventory_code
mmt.inventory_item_id
,s1.serial_number
=====================================
SELECT SUM (target_qty)
, item_id
FROM
(SELECT moqv.subinventory_code subinv
, moqv.inventory_item_id item_id
, SUM (transaction_quantity) target_qty
FROM
mtl_onhand_qty_cost_v moqv
WHERE
moqv.organization_id = :org_id
AND
moqv.inventory_item_id = :item_id
GROUP BY moqv.subinventory_code
, moqv.inventory_item_id
, moqv.item_cost
UNION
SELECT mmt.subinventory_code subinv
, mmt.inventory_item_id item_id
, -SUM (primary_quantity) target_qty
FROM
mtl_material_transactions mmt

, mtl_txn_source_types mtst
mmt.organization_id = :org_id
transaction_date >= TO_DATE (:hist_date) + 1
mmt.transaction_source_type_id =
mtst.transaction_source_type_id
AND
mmt.inventory_item_id = :item_id
GROUP BY mmt.subinventory_code
, mmt.inventory_item_id) oq
GROUP BY oq.item_id
WHERE
AND
AND

SELECT

moqv.subinventory_code subinv
, moqv.inventory_item_id item_id
, SUM (transaction_quantity) target_qty
FROM
mtl_onhand_qty_cost_v moqv
,mtl_system_items_b msi
WHERE
moqv.organization_id = 99
-- AND
moqv.inventory_item_id = :item_id
AND
moqv.inventory_item_id = msi.inventory_item_id
AND
moqv.organization_id = msi.organization_id
AND
msi.segment1
='HEF02NH019'
GROUP BY moqv.subinventory_code
, moqv.inventory_item_id
, moqv.item_cost
UNION
SELECT mmt.subinventory_code subinv
, mmt.inventory_item_id item_id
, -SUM (primary_quantity) target_qty
FROM
mtl_material_transactions mmt
, mtl_txn_source_types mtst
, mtl_system_items_b msi1
WHERE
mmt.organization_id = 99
AND
transaction_date >= TO_DATE ('31-dec-2013') + 1
AND
mmt.transaction_source_type_id = mtst.transaction_source_type

_id
--AND
mmt.inventory_item_id = :item_id
AND
msi1.segment1
='HEF02NH019'
AND
mmt.inventory_item_id = msi1.inventory_item_id
AND
mmt.organization_id = msi1.organization_id
GROUP BY mmt.subinventory_code
, mmt.inventory_item_id
=====================================================================
select * from cst_item_costs a
where a.inventory_item_id=614--604
and a.organization_id =93
select * from mtl_system_items_b b
where b.segment1='HEF02CL011'
select * from mtl_onhand_quantities_detail m
where m.organization_id=93
and m.inventory_item_id=273575
select * from mtl_unit_transactions mm
where mm.organization_id=93
and mm.inventory_item_id=2061
AND TRUNC(mm.TRANSACTION_DATE)<='31-DEC-2013'
and mm.serial_number in (2820508,2820547,2820548,2820549,2820550,2820551)

select * from mtl_onhand_serial_mwb_v s


where s.organization_id=93
and s.inventory_item_id=2061
select sum(i.transaction_quantity)
from mtl_material_transactions i-- ,mtl_unit_transactions mm
where i.inventory_item_id=2061--273575
and i.organization_id=93
--and mm.organization_id=i.organization_id
--and mm.inventory_item_id=i.inventory_item_id
--and (i.TRANSACTION_DATE)=mm.TRANSACTION_DATE
--and i.transaction_source_id=mm.transaction_source_id
AND TRUNC(i.TRANSACTION_DATE)<='31-DEC-2013'-- i.transaction_id=12583004
and i.transaction_source_type_id=13
select * from mtl_unit_transactions mm
where mm.organization_id=93
and mm.inventory_item_id=2061
AND TRUNC(mm.TRANSACTION_DATE)<='31-DEC-2013'
and mm.serial_number in (2820508,2820547,2820548,2820549,2820550,2820551)
-----------------SELECT b.segment1,m.transaction_date , sum(m.transaction_quantity),sum(m.transac
tion_quantity)*round(c.item_cost,2)/sum(m.transaction_quantity) ,s.serial_number
--SUM(NVL(M.TRANSACTION_QUANTITY ,0)* NVL( c.item_cost,0))
FROM MTL_MATERIAL_TRANSACTIONS M
,cst_item_costs c
,mtl_system_items_b b
,mtl_onhand_serial_mwb_v s
WHERE M.ORGANIZATION_ID=93
and m.inventory_item_id=c.inventory_item_id
and m.organization_id=c.organization_id
and b.inventory_item_id=c.inventory_item_id
and b.organization_id=c.organization_id
AND TRUNC(M.TRANSACTION_DATE)<='31-DEC-2013'
and s.inventory_item_id=c.inventory_item_id
and s.organization_id=c.organization_id
and s.last_transaction_id=m.transaction_id
group by b.segment1,c.item_cost,s.serial_number,m.transaction_date
having sum(transaction_quantity)>0
=====================================
SELECT b.segment1, sum(m.transaction_quantity)*round(c.item_cost,2) --SUM(NVL(M.
TRANSACTION_QUANTITY ,0)* NVL( c.item_cost,0))
FROM MTL_MATERIAL_TRANSACTIONS M
,cst_item_costs c
,mtl_system_items_b b
WHERE M.ORGANIZATION_ID=93
and m.inventory_item_id=c.inventory_item_id
and m.organization_id=c.organization_id
and b.inventory_item_id=c.inventory_item_id
and b.organization_id=c.organization_id
AND TRUNC(M.TRANSACTION_DATE)<='31-DEC-2013'
group by b.segment1,c.item_cost
having sum(transaction_quantity)>0
=========================================
sELECT b.segment1, sum(m.transaction_quantity)*round(c.item_cost,2)
FROM MTL_MATERIAL_TRANSACTIONS M
,cst_item_costs c
,mtl_system_items_b b

,mtl_transaction_lot_numbers L
-- ,mtl_unit_transactions u
WHERE M.ORGANIZATION_ID=93
and m.inventory_item_id=c.inventory_item_id
and m.organization_id=c.organization_id
and b.inventory_item_id=c.inventory_item_id
and b.organization_id=c.organization_id
AND TRUNC(M.TRANSACTION_DATE)<='31-DEC-2013'
--------------and m.inventory_item_id=l.inventory_item_id
and m.organization_id=l.organization_id
and m.inventory_item_id=l.inventory_item_id
and m.transaction_id =l.transaction_id
--------------------------------/*and u.inventory_item_id=l.inventory_item_id
and u.organization_id=l.organization_id
and u.inventory_item_id=l.inventory_item_id
and u.transaction_id =l.serial_transaction_id*/
----------------------group by b.segment1,c.item_cost
having sum(m.transaction_quantity)>0
order by b.segment1
===========================================================
Hi
please link the below tables to find the serial number
All Purchase receiving informations are captured in
RCV_SHIPMENT_HEADERS and RCV_SHIPMENT_LINES tables.
and it is linked to RCV_TRANSACTIONS table with SHIPMENT_HEADER_ID & SHIPMENT_L
INE_ID coloums
to find the lot and serial number the RCV_TRANSACTIONS table is linked to MTL_M
ATERIAL_TRANSACTIONS table with RCV_TRANSACTION_ID column and TRANSACTION_ID col
oumn is the link to MTL_SERIAL_NUMBERS table with LAST_TRANSACTION_ID coloumn.
======================================================
How to find Onhand Quantity at given date?

The following query displays the onhand quantity information.


The query inputs the Item ID, organization ID and date.
SELECT

SUM (target_qty)
, item_id
FROM
(SELECT moqv.subinventory_code subinv
, moqv.inventory_item_id item_id
, SUM (transaction_quantity) target_qty
FROM
mtl_onhand_qty_cost_v moqv
WHERE
moqv.organization_id = :org_id
AND
moqv.inventory_item_id = :item_id
GROUP BY moqv.subinventory_code
, moqv.inventory_item_id
, moqv.item_cost
UNION
SELECT mmt.subinventory_code subinv
, mmt.inventory_item_id item_id

, -SUM (primary_quantity) target_qty


mtl_material_transactions mmt
, mtl_txn_source_types mtst
WHERE
mmt.organization_id = :org_id
AND
transaction_date >= TO_DATE (:hist_date) + 1
AND
mmt.transaction_source_type_id =
mtst.transaction_source_type_id
AND
mmt.inventory_item_id = :item_id
GROUP BY mmt.subinventory_code
, mmt.inventory_item_id) oq
GROUP BY oq.item_id
=====================================================
select a.*
from mtl_serial_numbers_all_v a, mtl_system_items_b b
where a.current_organization_id = 93
and b.inventory_item_id = a.inventory_item_id
and b.organization_id = a.current_organization_id
and (a.ship_date is null or trunc(a.ship_date) > '31-dec-2013')
and a.request_id is not null
-- and b.segment1 = 'HEF02TU002'
FROM

You might also like