SELECT KKVW.BUSINESS_UNIT , KKVW.REQ_ID , SUM(KKVW.ENCUM_BALANCE) , KKVW.CURRENCY_CD , SUM(KKVW.FOREIGN_AMOUNT) FROM PS_PO_KK_VW KKVW LEFT JOIN PS_REQ_LN_DISTRIB DIS ON KKVW.BUSINESS_UNIT = DIS.BUSINESS_UNIT AND KKVW.REQ_ID = DIS.REQ_ID AND KKVW.LINE_NBR = DIS.LINE_NBR AND KKVW.SCHED_NBR = DIS.SCHED_NBR AND KKVW.DISTRIB_LINE_NUM = DIS.DISTRIB_LINE_NUM JOIN PS_REQ_HDR REQHDR ON KKVW.REQ_ID = REQHDR.REQ_ID AND KKVW.BUSINESS_UNIT = REQHDR.BUSINESS_UNIT WHERE EXISTS ( SELECT 'X' FROM PS_KK_ACTIVITY_LOG ACT , PS_BUL_CNTL_BUD LED WHERE ACT.BUSINESS_UNIT = LED.BUSINESS_UNIT AND ACT.KK_TRAN_ID = KKVW.KK_TRAN_ID AND ACT.KK_TRAN_DT = KKVW.KK_TRAN_DT AND ACT.LEDGER_GROUP = KKVW.LEDGER_GROUP AND LED.KK_LEDGER_GROUP = KKVW.LEDGER_GROUP AND LED.KK_DETAIL_LED = 'Y') GROUP BY KKVW.BUSINESS_UNIT, KKVW.REQ_ID, KKVW.CURRENCY_CD
|