Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Formatting numeric results with commas

Author  Topic 

mj
Starting Member

25 Posts

Posted - 2002-07-10 : 10:38:44
Is it possible to have a numeric result formatted with commas in a recordset returned from a stored procedure, or any recordset for that matter.

e.g. 3000000.00 would look like 3,000,000.00

I'm sure there is probably an easy answer to this, but I haven't been able to find it.

Thanks

mj

rihardh
Constraint Violating Yak Guru

307 Posts

Posted - 2002-07-10 : 10:55:24
My opinion is that formating always takes place at the front-end. The format of numbers in the database is determined by the DB collation. As far as my knowledge goes, you can't get your desired format of numbers in the DB. Format them in the front-end control(text box, grid,...).

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-07-10 : 10:56:13
Sure, the CONVERT function will do it:

SELECT CONVERT(varchar(15), CONVERT(money, numericValue), 1)

You have to convert the number to money datatype in order to include the commas. Look in Books Online for more details on CONVERT.

SNIPED!

Actually, I agree on the front-end formatting too, you really should put it there instead of having SQL Server do it, unless you don't have that option.

Edited by - robvolk on 07/10/2002 10:57:17
Go to Top of Page

MakeYourDaddyProud

184 Posts

Posted - 2002-07-10 : 10:58:33
Yep. How is the recordset presented to the user. Is it a form, report or what. Preformatting does not take at db level, it is a presentation issue. If you are using VB, there is a FORMAT statement available to you, whereas Crystal has a designer for numeric fields allowing many types of display form...

Daniel Small MIAP
www.danielsmall.com IT Factoring
Go to Top of Page

mj
Starting Member

25 Posts

Posted - 2002-07-10 : 11:06:25
Rob,
Thanks, I figured this out just as soon as I had posted.
I would normally do the formatting on the front end, but this way is much easier with the scenario I'm using.

mj

Go to Top of Page
   

- Advertisement -