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
Varshini SAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian CroweDatabase AdministratorCommented:
SELECT CAST(totalamt AS DECIMAL(9,2)) AS TotalAmount
FROM table1

OR

SELECT ROUND(totalamt, 2) AS TotalAmount
FROM table1
Varshini SAuthor Commented:
Brain,
I need the output in varchar
Brian CroweDatabase AdministratorCommented:
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
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Varshini SAuthor Commented:
I am exporting the output to CSV.  So the column should be string.
Varshini SAuthor Commented:
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
Brian CroweDatabase AdministratorCommented:
Use the CAST to DECIMAL instead, it also handles rounding.

SELECT CAST(CAST(totalamt AS DECIMAL(9,2)) AS VARCHAR) AS TotalAmount
FROM table1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PortletPaulEE Topic AdvisorCommented:
if it is available to you (version SQL 2012 onward) try FORMAT()

e.g.

FORMAT(totalamt,'0.00')
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.