Varshini S
asked on
SQL query output only need two decimal places
select convert(varchar,totalamt ) as TotalAmount from table1
Output: 18882.019
15882.050
8078.816
I need the output in the following format (need only two decimal places). How do i achieve this ?
18882.01
15882.05
8078.81
Output: 18882.019
15882.050
8078.816
I need the output in the following format (need only two decimal places). How do i achieve this ?
18882.01
15882.05
8078.81
ASKER
Brain,
I need the output in varchar
I need the output in varchar
I first question is "Why?" since this should be handled at the presentation layer but just wrap it in a CONVERT/CAST to varchar.
SELECT CAST(ROUND(totalamt, 2) AS VARCHAR) AS TotalAmount
FROM table1
SELECT CAST(ROUND(totalamt, 2) AS VARCHAR) AS TotalAmount
FROM table1
ASKER
I am exporting the output to CSV. So the column should be string.
ASKER
I have used the below script. But the output still showing the third decimal 0
SELECT CAST(ROUND(totalamt, 2) AS VARCHAR) AS TotalAmount
FROM table1
Output:
834.200
3015.380
SELECT CAST(ROUND(totalamt, 2) AS VARCHAR) AS TotalAmount
FROM table1
Output:
834.200
3015.380
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
FROM table1
OR
SELECT ROUND(totalamt, 2) AS TotalAmount
FROM table1