SELECT
I.ACNTCTGR_CD
, DECODE(J.DBCR_SE_CD, '1', I.DR_AMT - I.CR_AMT
, '2', I.CR_AMT - I.DR_AMT
, 0 ) AS AMT
FROM (
SELECT
B.ACNTCTGR_CD
, SUM(DECODE(DC_DIV,'1',NVL(B.DEBIT_AMT,0),0)) AS DR_AMT
, SUM(DECODE(DC_DIV,'2',NVL(B.CREDIT_AMT,0),0)) AS CR_AMT
FROM TB_FSM100 A
, TB_FSM101 B
WHERE A.ACC_UNIT_CD LIKE '1000'
AND A.EPN_DT BETWEEN '201401'||'01' AND '201412'||'31'
AND A.USE_YN = 'Y'
AND A.APVL_STAT = '51'
AND A.CHIT_NO = B.CHIT_NO
AND B.USE_YN = 'Y'
AND A.CHIT_DIV = '3'
-->요기부터
AND CASE WHEN SUBSTR(A.EPN_DT,5,2) = '12' AND A.CHIT_TYPE IN ('11','14') THEN '1'
WHEN SUBSTR(A.EPN_DT,5,2) <> '12' AND A.CHIT_TYPE IN ('11','12','14') THEN '1'
ELSE '0'END = '1'
-->여기까지
GROUP BY B.ACNTCTGR_CD
) I
, TB_FSC010 J
WHERE I.ACNTCTGR_CD = J.ACNTCTGR_CD
위 쿼리에서 요기부터라는 부분의 AND절을 B.ACNTCTGR_CD = '000000' 값인경우는
WHERE절에서 AND절을 안타고 그외인경우만 AND절을 태우고 싶은데.. .쿼리가 안되는데요..
도와주세요...
|