Reputation: 1055
I run the below query.....
SELECT SUM(PAPostedTotalCostN) AS Total_Cost
FROM PA01201
WHERE PA01201.PAcontid = '00900'
which returns the value 12169298.25000
what is the simplest way to get the query to return any number to two decimals?
using the same return value as an example I would like to see the number appear as 12169298.25
The query will be used to return many numbers based on 'PAcontid' so i need to have the entire column of 'PAPostedTotalCostN' to be to 2 decimal places
any help much appreciated.
Upvotes: 0
Views: 19036
Reputation: 114
SELECT u.name, CAST( SUM( e.amount * er.tlkarsiligi ) AS DECIMAL( 10, 2 ) ) from ..
For It works on Mysql
Upvotes: 0
Reputation: 247720
You can CAST
is as a decimal with 2 places:
select CAST(PAPostedTotalCostN as decimal(20, 2))
Example:
declare @t as decimal(20, 5)
set @t = 12169298.250000
select cast(@t as decimal(20, 2))
Result:
12169298.25
This will round the result if the value at the can be rounded, if you do not want it to be rounded:
select cast(round(@t, 2, 1) as decimal(20, 2))
Upvotes: 0
Reputation: 10105
SELECT CONVERT(DECIMAL(10,2),SUM(PAPostedTotalCostN)) AS Total_Cost
FROM PA01201
WHERE PA01201.PAcontid = '00900'
Upvotes: 6
Reputation: 13775
http://msdn.microsoft.com/en-us/library/ms175003.aspx
You can use the ROUND function:
ROUND ( numeric_expression , length [ ,function ] )
Upvotes: 0