elsenorjose
Technical User
Hello gurus,
I am trying to write a query using 3 CASE statements to sum amounts for charges, payments, and adjustments and I want to then compare the values to find records where there is a $0 payments amount and adjustments = charges. My attempt at this results in an error message:
My SQL query:
Apparently I cannot do comparisons on the aliases for my CASE statements. Can someone provide direction on how I can accomplish my desired result?
Using Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi.
Thank you.
I am trying to write a query using 3 CASE statements to sum amounts for charges, payments, and adjustments and I want to then compare the values to find records where there is a $0 payments amount and adjustments = charges. My attempt at this results in an error message:
Code:
ORA-00904: "CHARGES": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 22 Column: 19
My SQL query:
Code:
SELECT DISTINCT
TDL.TX_ID,
TDL.ORIG_SERVICE_DATE,
TDL.ORIG_POST_DATE,
TDL.TX_NUM,
TDL.PROC_ID,
TDL.DETAIL_TYPE,
CLARITY.ACCOUNT.ACCOUNT_ID,
CASE WHEN TDL.DETAIL_TYPE IN (1, 10) THEN SUM(AMOUNT) END AS CHARGES,
CASE WHEN TDL.DETAIL_TYPE IN (2, 5, 11, 20, 22, 32, 33) THEN SUM(AMOUNT) END AS PAYMENTS,
CASE WHEN TDL.DETAIL_TYPE IN (3, 4, 6, 12, 13, 21, 23, 30, 31) THEN SUM(AMOUNT) END AS ADJUSTMENTS
FROM
CLARITY.CLARITY_TDL_TRAN TDL,
CLARITY.ACCOUNT
WHERE TDL.ACCOUNT_ID = ACCOUNT.ACCOUNT_ID
AND TDL.SERV_AREA_ID = 10
AND TDL.POST_DATE BETWEEN '01-APR-2012' AND '30-APR-2012'
AND PAYMENTS = 0
AND (ADJUSTMENTS = CHARGES)
GROUP BY
TDL.TX_ID,
TDL.ORIG_SERVICE_DATE,
TDL.ORIG_POST_DATE,
TDL.TX_NUM,
TDL.PROC_ID,
TDL.DETAIL_TYPE,
CLARITY.ACCOUNT.ACCOUNT_ID
Apparently I cannot do comparisons on the aliases for my CASE statements. Can someone provide direction on how I can accomplish my desired result?
Using Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi.
Thank you.