?
Solved

how to convert decimal value in to comma seperated value.

Posted on 2004-10-07
7
Medium Priority
?
655 Views
Last Modified: 2009-07-29
How to write select statment for DECIMAL(28,2) field with "," every thousands place.

For Example

Select QTY from mytable
QTY
----------------------
256110054720.21

Output should be
QTY
-----
256,110,054,720.21

0
Comment
Question by:Bharat Guru
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 26

Expert Comment

by:Hilaire
ID: 12250026
Presentation issues should be handled on the front-end side.
If you change amounts into strings, they wont sort properly, they won't sum any more , ...
0
 

Author Comment

by:Bharat Guru
ID: 12250071
you are right byt how can i convert in select statment.
somethinkg like this....
select convert(qty,...) from my table
0
 
LVL 17

Expert Comment

by:BillAn1
ID: 12250102
if you are looking at the result in Query Analyser, you can have it formatted according to your local settings by going to tools->options->connections and select the "use regional settings" option. Then, make sure your reginal settings (from Control Panel) have comma seperator etc.
If you are passing the results on to an application, you are much better off have the application do the formatting, as otherwise you would have to change the data type from decimal to varchar()  etc.
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 26

Expert Comment

by:Hilaire
ID: 12250158
There's no built-in support for this format
instead, most programming languages have formatNumber or formatCurrency functions,
and most reporting tools including excel have standard supprto for htis kind of display format

This could be achieved with a user-defined funciton that would
- cast the number as a string
- find decimal point, if any
- loop every 3 digits left
- build the string in the loop

The function will be ugly and performances will be affected badly

Do you really want this ?
0
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 80 total points
ID: 12250304
I agree that it's better to do it in the front end, but you can do it in a SELECT statement. Use CONVERT with a style argument of 1, and the value being converted has to be a money datatype, so if the original value isn't money, you have to CAST it before the CONVERT function does it's thing:

DECLARE @d as decimal(20,2)
SET @d = 256110054720.21
SELECT Convert(varchar(50), Cast(@d as money) ,1)
0
 
LVL 26

Expert Comment

by:Hilaire
ID: 12250501
>>The function will be ugly and performances will be affected badly<<
Forgive me for this mis-appreciation

jdlambert has a cool way to get the output you need, and I've learnt something new today ;-)
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12250520
My memory's so bad, everything I learn is new...  :)
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

770 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