0% found this document useful (0 votes)
497 views2 pages

OnHand Balance Query B4alias

This SQL query retrieves on-hand inventory information including quantity on hand, unit cost, currency, extended value, category, lot status, and lot origination and expiration dates for an organization. It joins several tables including item, cost, category, on-hand quantity, and lot number tables to return the aggregated results for an organization, item, subinventory, and lot. The results are ordered by organization and item number.
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)
497 views2 pages

OnHand Balance Query B4alias

This SQL query retrieves on-hand inventory information including quantity on hand, unit cost, currency, extended value, category, lot status, and lot origination and expiration dates for an organization. It joins several tables including item, cost, category, on-hand quantity, and lot number tables to return the aggregated results for an organization, item, subinventory, and lot. The results are ordered by organization and item number.
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/ 2

-- Onhand with COST

WITH cst AS (
SELECT
item.organization_id,
item.inventory_item_id,
cscv.currency_code currency,
cscv.total_cost unit_cost,
cscv.effective_start_date,
cscv.effective_end_date
FROM
cst_std_costs cscv,
cst_cost_org_books ccob,
cst_cost_inv_orgs ccio,
cst_val_units_b cvub,
inv_org_parameters param,
egp_system_items_b item
WHERE
1 = 1
and item.organization_id = ccio.inv_org_id
AND ccio.cost_org_id = ccob.cost_org_id
AND ccob.cost_org_id = cscv.cost_org_id
AND ccob.cost_book_id = cscv.cost_book_id
AND cvub.cost_book_id = ccob.cost_book_id
AND cvub.cost_org_id = ccob.cost_org_id
AND cvub.val_unit_id = cscv.val_unit_id
AND item.inventory_item_id = cscv.inventory_item_id
AND item.organization_id = param.organization_id
AND cscv.status_code = 'PUBLISHED'
AND SYSDATE BETWEEN cscv.effective_start_date AND cscv.effective_end_date
), cat AS(

SELECT
eic.inventory_item_id inventory_item_id,
eic.category_id,
eic.organization_id organization_id,
ecv.category_name category_name,
ecv.category_code,
ecs.category_set_name
FROM
egp_item_categories eic,
egp_default_category_sets edc,
egp_categories_vl ecv
,
egp_category_sets_vl ecs
WHERE
eic.category_set_id = edc.category_set_id
AND edc.functional_area_id = 1 /* Inventory 1 Costing 5 both point
to same in Aimmune implementation*/
AND eic.category_id = ecv.category_id
AND edc.category_set_id = ecs.category_set_id
)
,oh AS (
SELECT
ohd.organization_id,
ohd.inventory_item_id,
ohd.subinventory_code,
SUM(ohd.primary_transaction_quantity) qty,
ohd.lot_number
FROM
inv_onhand_quantities_detail ohd
WHERE
1 = 1
GROUP BY
ohd.organization_id,
ohd.inventory_item_id,
ohd.subinventory_code,
ohd.lot_number
)
SELECT
p.organization_code organization,
item.item_number,
uom.unit_of_measure puom,
oh.subinventory_code,
oh.lot_number,iln.ORIGINATION_DATE Lot_Origination_Date,iln.EXPIRATION_DATE
Lot_Expiration_Date,cat.category_name category_name,
ivms.status_code lot_status,
round(nvl(oh.qty, 0), 2) qty,
round(nvl(cst.unit_cost, 0), 5) cost,
cst.currency currency,
round(nvl(oh.qty, 0) * nvl(cst.unit_cost, 0), 2) extended_value
FROM
inv_org_parameters p,
egp_system_items_vl item,
oh oh,
cst cst,
inv_units_of_measure_vl uom,
inv_lot_numbers iln,
inv_material_statuses_vl ivms,
cat cat
WHERE
1 = 1
AND item.organization_id = p.organization_id
AND p.organization_id != p.master_organization_id
AND item.organization_id = oh.organization_id (+)
AND item.inventory_item_id = oh.inventory_item_id (+)
AND item.organization_id = cst.organization_id (+)
AND item.inventory_item_id = cst.inventory_item_id (+)
AND item.primary_uom_code = uom.uom_code
AND oh.organization_id = iln.organization_id (+)
AND oh.lot_number = iln.lot_number (+)
AND iln.status_id = ivms.status_id (+)
and item.organization_id = cat.organization_id (+)
AND item.inventory_item_id = cat.inventory_item_id (+)
ORDER BY
1,
2

You might also like