Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to convert add decimals at result data in sqlserver?

Posted on 2010-09-02
5
Medium Priority
?
328 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 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

916 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