?
Solved

How to convert add decimals at result data in sqlserver?

Posted on 2010-09-02
5
Medium Priority
?
325 Views
Last Modified: 2012-05-10
My data like:
Product#
78.5
92
11.28
I want Reslut like
Product#
78.50
92.00
11.28
0
Comment
Question by:rite2mis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 2000 total points
ID: 33593985
select convert(decimal(9,2),ColumnName) from TableName
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33594077
select CAST(ColumField AS DECIMAL(6,2)) from Product
0
 
LVL 8

Expert Comment

by:avirups
ID: 33594084
dale_burrell has already given you CONVERT

You can also use CAST.

Follow the link to get more details on both CAST and CONVERT: http://msdn.microsoft.com/en-us/library/ms187928.aspx
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 33594220
Generally you shouldn't format the data when you get it from the database, that's a task for the user interface.

Anyhow, to format the data that way, you first make sure that the field is in a numeric format that supports two decimal positions, then you convert it to a string.

If the type of the field is already something like decimal(9,2), then you just convert it to a string

  select convert(varchar, theField) ...

Otherwise you need two conversions

  select convert(varchar, convert(decimal(9,2), theField)) ...
0
 

Author Closing Comment

by:rite2mis
ID: 33594641
Nice reply
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question