Taylor
Taylor

Reputation: 11

Decimal Formatting

Hello stack overflow members, I have an issue I'm dealing with and am not sure how to fix it. So I have this SQL code:

SELECT ABS(SUM(TO_CHAR(a1.test_amount, '99999.00'))) AS "Test Amt"
FROM test a1
WHERE a1.test_id = '102434'
AND a1.test_detail_code IN ('2334','2335','2336')
AND a1.test_period = '201501'

All I'm trying to do is convert the a1.test_amount into a format with two decimal places. When I do TO_CHAR with the following, it works fine.

SELECT TO_CHAR(1450, '99999.00')
FROM dual
----------
1450.00

That leads me to believe it has something to do with the SUM? Any help would be greatly appreciated!

Upvotes: 0

Views: 74

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269773

Do the conversion after the arithmetic:

SELECT TO_CHAR(ABS(SUM(a1.test_amount)), '99999.00') AS "Test Amt"
FROM . . .

Upvotes: 0

Vamsi Prabhala
Vamsi Prabhala

Reputation: 49260

Use to_char after performing the sum operation.

TO_CHAR(ABS(SUM(a1.test_amount)),'99999.00')

Upvotes: 5

Related Questions