Query to handle with zero if no onhand quantities in Inventory or onhand is NULL

Objective:

Query to handle with zero if no onhand quantities in Inventory or onhand is NULL

 

SQL:

Select NVL(MAX(COUNT(moq.TRANSACTION_QUANTITY)),0) –MAX(NVL(SUM(moq.TRANSACTION_QUANTITY),0))
from mtl_onhand_quantities moq, MTL_ITEM_LOCATIONS_KFV mil, mtl_system_items_b msib
where moq.LOCATOR_ID = mil.INVENTORY_LOCATION_ID
and moq.inventory_item_id = msib.inventory_item_id
and msib.ORGANIZATION_ID = 16195
and msib.segment1 = ‘009191-702-884’–ITEMCODE
and moq.SUBINVENTORY_CODE = ‘STORE’–SUBINV
AND mil.CONCATENATED_SEGMENTS = ‘A01.02.01…’–LOC
GROUP BY moq.TRANSACTION_QUANTITY

 

Recent Posts