SELECT moa.organization_id, moa.inventory_item_id, organization_code,msi.segment1 item_code,
organization_name, primary_unit_of_measure_tl, assigned_flag,
moa.cost_of_sales_account, moa.sales_account, moa.expense_account,
moa.encumbrance_account
FROM mtl_org_assign_v moa
,mtl_system_items_b msi
WHERE master_organization_id = 1823 --master organization
AND msi.inventory_item_id = moa.inventory_item_id
AND msi.organization_id = moa.organization_id
AND (NVL (eam_enabled_flag, 'N') = NVL ('N', 'N') OR NVL ('N', 'N') = 'N')
AND EXISTS (
SELECT 'x'
FROM hr_organization_information ood
WHERE ood.organization_id = moa.organization_id
AND ood.org_information2 = 'Y'
AND ood.org_information1 = 'INV'
AND (ood.org_information_context || '') = 'CLASS')
ORDER BY msi.segment1,--DECODE (organization_id, 1990, 1, 2) ASC,
moa.assigned_flag DESC,
moa.organization_code