SELECT A.BUSINESS_UNIT , A.INV_ITEM_ID , SUM(B.QTY_PEGGED - B.QTY_COMPLETE) FROM PS_BU_ITEMS_INV A , PS_IN_PEGGING B WHERE B.PEG_STATUS = '10' AND ((B.DMD_ORDER_TYPE = '070' OR B.DMD_ORDER_TYPE = '090' OR B.DMD_ORDER_TYPE = '030') AND EXISTS ( SELECT 'X' FROM PS_IN_DEMAND_HASH IDH WHERE IDH.HASH_KEY = B.DEMAND_HASH AND IDH.BUSINESS_UNIT = A.BUSINESS_UNIT AND IDH.INV_ITEM_ID = A.INV_ITEM_ID) OR (B.DMD_ORDER_TYPE = '110' AND EXISTS ( SELECT 'X' FROM PS_WM_WO_MAT_HASH WWMH , PS_WM_WO_SCHED_MAT WWSM WHERE WWMH.HASH_KEY = B.DEMAND_HASH AND WWSM.BUSINESS_UNIT = WWMH.BUSINESS_UNIT AND WWSM.WO_ID = WWMH.WO_ID AND WWSM.WO_TASK_ID = WWMH.WO_TASK_ID AND WWSM.RES_LN_NBR = WWMH.RES_LN_NBR AND WWSM.BUSINESS_UNIT_IN = A.BUSINESS_UNIT AND WWSM.INV_ITEM_ID = A.INV_ITEM_ID))) GROUP BY A.BUSINESS_UNIT, A.INV_ITEM_ID
|