SELECT S.CRSPD_SETID AS CRSPD_SETID , S.CRSPD_CUST_ID AS CRSPD_CUST_ID , SD.BUSINESS_UNIT AS BUSINESS_UNIT , S.ST_ID_NUM AS ST_ID_NUM , S.ST_DT AS ST_DT , SUM(SD.BAL_AMT) AS BAL_AMT , SD.BAL_CURRENCY AS BAL_CURRENCY , 0 AS TOTAL_ROW_COUNT , %CurrentDateTimeIn AS ROW_ADDED_DTTM , %OperatorId AS ROW_ADDED_OPRID , %CurrentDateTimeIn AS ROW_LASTMANT_DTTM , %OperatorId AS ROW_LASTMANT_OPRID , 0 AS SYNCID , %CurrentDateTimeIn AS SYNCDTTM FROM PS_STMT_CUST S , PS_STMT_CUST_DTL SD WHERE S.CRSPD_SETID = SD.CRSPD_SETID AND S.CRSPD_CUST_ID = SD.CRSPD_CUST_ID AND S.ST_ID_NUM = SD.ST_ID_NUM GROUP BY S.CRSPD_SETID, S.CRSPD_CUST_ID, SD.BUSINESS_UNIT, S.ST_ID_NUM, S.ST_DT, SD.BAL_CURRENCY UNION ALL SELECT DISTINCT S1.CRSPD_SETID AS CRSPD_SETID , S1.CRSPD_CUST_ID AS CRSPD_CUST_ID , SD1.BUSINESS_UNIT AS BUSINESS_UNIT , S1.ST_ID_NUM AS ST_ID_NUM , S1.ST_DT AS ST_DT , 0 AS BAL_AMT , SD1.BALFWD_BAL_CUR AS BAL_CURRENCY , 0 AS TOTAL_ROW_COUNT , %CurrentDateTimeIn AS ROW_ADDED_DTTM , %OperatorId AS ROW_ADDED_OPRID , %CurrentDateTimeIn AS ROW_LASTMANT_DTTM , %OperatorId AS ROW_LASTMANT_OPRID , 0 AS SYNCID , %CurrentDateTimeIn AS SYNCDTTM FROM PS_STMT_CUST S1 , PS_STMT_CUST_BFWD SD1 WHERE S1.CRSPD_SETID = SD1.CRSPD_SETID AND S1.CRSPD_CUST_ID = SD1.CRSPD_CUST_ID AND S1.ST_ID_NUM = SD1.ST_ID_NUM AND NOT EXISTS ( SELECT SS.ST_ID_NUM FROM PS_STMT_CUST_DTL SS WHERE S1.CRSPD_SETID = SS.CRSPD_SETID AND S1.CRSPD_CUST_ID = SS.CRSPD_CUST_ID AND S1.ST_ID_NUM = SS.ST_ID_NUM)
|