Link to home
Start Free TrialLog in
Avatar of rite2mis
rite2mis

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Dale Burrell
Dale Burrell
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
select CAST(ColumField AS DECIMAL(6,2)) from Product
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
Avatar of Göran Andersson
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)) ...
Avatar of rite2mis
rite2mis

ASKER

Nice reply