Solved

How to convert add decimals at result data in sqlserver?

Posted on 2010-09-02
5
316 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL LINE CONTINUATION ISSUE 12 31
Addition to SQL for dynamic fields 6 36
SSRS Subscription jobs disabled, yet still running 4 30
Find SQL query used by application 3 16
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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

816 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

10 Experts available now in Live!

Get 1:1 Help Now