SELECT A.BUSINESS_UNIT , A.EXT_ORG_ID , A.AGING_SET , A.AGE_CATEGORY , B.DESCR , SUM(AMOUNT) FROM PS_CREDIT_HISTORY A , PS_AGING_CAT_TBL B WHERE A.EXT_ORG_ID > ' ' AND B.SETID = ( SELECT C.SETID FROM PS_SET_CNTRL_REC C WHERE C.SETCNTRLVALUE=A.BUSINESS_UNIT AND C.REC_GROUP_ID = 'AGING' AND C.RECNAME='AGING_CAT_TBL') AND A.AGING_SET = B.AGING_SET AND A.AGE_CATEGORY = B.AGE_CATEGORY AND A.EFFDT = ( SELECT MAX(D.EFFDT) FROM PS_CREDIT_HISTORY D WHERE D.BUSINESS_UNIT = A.BUSINESS_UNIT AND D.EXT_ORG_ID = A.EXT_ORG_ID AND D.AGING_SET = A.AGING_SET AND D.EFFDT <= %CurrentDateIn) GROUP BY A.BUSINESS_UNIT, A.EXT_ORG_ID , A.AGING_SET, A.AGE_CATEGORY, B.DESCR
|