SELECT A.TERM_SCHED_ID , A.SEQ_NUM , A.ASSET_SEQ_NBR , MAX(B.DISTRIBUTION_ID) , SUM( CASE WHEN (B.DISTRIBUTION_ID IS NULL OR A.DISTRIBUTION_ID = B.DISTRIBUTION_ID ) THEN 0 ELSE %Sql(RE_DISTRIB_AMT_CALC, A.DECIMAL_POSITIONS, %SQL(RE_RNDFLG_AMT_SEL, A.ROUNDING_APPLIED, A.AMOUNT_1, C.INTEREST_EXPENSE, A.INTEREST_EXPENSE), A.PERCENTAGE) END) , SUM( CASE WHEN (B.DISTRIBUTION_ID IS NULL OR A.DISTRIBUTION_ID = B.DISTRIBUTION_ID ) THEN 0 ELSE %Sql(RE_DISTRIB_AMT_CALC, A.DECIMAL_POSITIONS, %SQL(RE_RNDFLG_AMT_SEL, A.ROUNDING_APPLIED, A.AMOUNT_2, C.INTEREST_ACCRUAL, A.INTEREST_ACCRUAL), A.PERCENTAGE) END) , SUM( CASE WHEN (B.DISTRIBUTION_ID IS NULL OR A.DISTRIBUTION_ID = B.DISTRIBUTION_ID ) THEN 0 ELSE %Sql(RE_DISTRIB_AMT_CALC, A.DECIMAL_POSITIONS, %SQL(RE_RNDFLG_AMT_SEL, A.ROUNDING_APPLIED, A.AMOUNT_3, C.AMORTIZATION_AMT, A.AMORTIZATION_AMT), A.PERCENTAGE) END) FROM PS_RE_LS_PINSUM_VW C RIGHT OUTER JOIN PS_RE_LS_AM_PIN_VW A ON (C.TERM_SCHED_ID = A.TERM_SCHED_ID AND C.SEQ_NUM = A.SEQ_NUM) LEFT OUTER JOIN PS_RE_LS_DS_RND_VW B ON (A.LS_KEY = B.LS_KEY AND A.AMND_NBR = B.AMND_NBR AND A.ASSET_SEQ_NBR = B.ASSET_SEQ_NBR) GROUP BY A.TERM_SCHED_ID , A.SEQ_NUM , A.ASSET_SEQ_NBR
|