Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • 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

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

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