February 19, 2004 at 4:55 pm
I'm trying to ROUND to 2 Decimal Places. The query is below. The Value Column is a MONEY DataType!
When I execute the query below, it doesn't ROUND to 2 Decimal Places. THe result is the same, it has 4 digits after the decimal!
Is there a trick to this?
SELECT AccountID, ROUND(SUM(CASE WHEN Value < 0 THEN Value ELSE 0 END), 2) AS 'Debit',
ROUND(SUM(CASE WHEN Value > 0 THEN Value ELSE 0 END), 2) AS 'Credit'
FROM Invoices
GROUP BY AccountID
February 19, 2004 at 6:26 pm
Use convert to truncate.
February 19, 2004 at 6:46 pm
February 20, 2004 at 6:30 am
Money will always be displayed with four decimal places whether rounded or not
12.3456
will be 12.3456
or 12.3500 when rounded to 2 decimal places
if you want the values to have two decimal places cast them to decimal
SELECT AccountID,
CAST(ROUND(SUM(CASE WHEN Value < 0 THEN Value ELSE 0 END), 2) AS decimal(9,2)) AS 'Debit',
CAST(ROUND(SUM(CASE WHEN Value > 0 THEN Value ELSE 0 END), 2) AS decimal(9,2)) AS 'Credit'
FROM #Invoices
GROUP BY AccountID
Far away is close at hand in the images of elsewhere.
Anon.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply