SELECT I.OPRID , I.BUSINESS_UNIT , I.SETID , I.RESP_PART , I.TRANS_CURRENCY , SUM(I.BAL_AMT) , SUM(I.ITEM_CNT) , SUM(I.DISPLAY_BAL_AMT) , I.DISPLAY_CURRENCY FROM PS_DBTIT_OPBAL_VW I , PS_ARFO_PRF_DBTIT S WHERE S.OPRID = I.OPRID AND ( S.BU_SELECT_FLG = 'A' OR EXISTS ( SELECT 'X' FROM PS_ARFO_PRF_DBT_BU BU WHERE BU.OPRID = I.OPRID AND BU.BUSINESS_UNIT = I.BUSINESS_UNIT) ) AND ( S.RESP_ALL_FLG = 'A' OR EXISTS ( SELECT 'X' FROM PS_ARFO_PRFDBT_RSP R WHERE R.OPRID = I.OPRID AND R.RESP_PART = I.RESP_PART) ) AND (S.CUST_SELECT_FLG = 'A' OR (S.CUST_SELECT_FLG = 'G' AND ( (S.BLK_CUST_GRP = 'Y' AND NOT EXISTS ( SELECT 'X' FROM PS_CUST_CGRP_LNK G , PS_AR_BUSET_MVW E WHERE E.SETCNTRLVALUE = I.BUSINESS_UNIT AND E.RECNAME = 'CUSTOMER' AND E.SETID = G.SETID AND I.CUST_ID = G.CUST_ID ) ) OR EXISTS ( SELECT 'X' FROM PS_ARFO_PRFDBT_CUG CUST , PS_CUST_CGRP_LNK G , PS_AR_BUSET_MVW E WHERE E.SETCNTRLVALUE = I.BUSINESS_UNIT AND E.RECNAME = 'CUSTOMER' AND I.OPRID = CUST.OPRID AND E.SETID = G.SETID AND I.CUST_ID = G.CUST_ID AND G.SETID = CUST.SETID AND G.CUST_GRP_TYPE = CUST.CUST_GRP_TYPE AND G.CUSTOMER_GROUP = CUST.CUSTOMER_GROUP ) ) ) ) GROUP BY I.OPRID , I.BUSINESS_UNIT , I.SETID , I.RESP_PART , I.TRANS_CURRENCY , I.DISPLAY_CURRENCY
|