• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 336
  • Last Modified:

How to convert add decimals at result data in sqlserver?

My data like:
Product#
78.5
92
11.28
I want Reslut like
Product#
78.50
92.00
11.28
0
rite2mis
Asked:
rite2mis
1 Solution
 
Dale BurrellDirectorCommented:
select convert(decimal(9,2),ColumnName) from TableName
0
 
Mohit VijayCommented:
select CAST(ColumField AS DECIMAL(6,2)) from Product
0
 
avirupsCommented:
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
 
Göran AnderssonCommented:
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
 
rite2misAuthor Commented:
Nice reply
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now