Solved

How to convert add decimals at result data in sqlserver?

Posted on 2010-09-02
5
314 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
5 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 500 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

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now