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 numbers

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-05-17 : 10:06:44
Balaji writes "Hi,

I want to format 10000000.00 as 10,000,000.00 when selecting 10000000.00. Is there a way to do it in t-sql?

Regds
Balaji.v"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-05-17 : 10:17:41
Sure! The CONVERT() function also allows for some basic number formatting, but it only works on money or smallmoney data (not float or real), so you might have to do 2 conversions:

SELECT Convert(varchar(15), Convert(money, 10000000.00), 1)

Look in Books Online under CONVERT for more details.

OOOOOOOOOOOOOOOOOOOOOOOOPS!

I goofed, use 1 for the CONVERT statement instead of 2 (I edited it above, I've tested it now and it works!)

Edited by - robvolk on 05/17/2002 10:32:13
Go to Top of Page

VyasKN
SQL Server MVP & SQLTeam MVY

313 Posts

Posted - 2002-05-17 : 10:21:45
I think it's a bit difficult to do this with CONVERT. Give this a try:

DECLARE @val varchar(20)
SET @val = '10000000.00'
SELECT REVERSE(STUFF(STUFF(REVERSE(convert(varchar(20),@val)), 7, 0, ','), 11, 0, ','))

--
HTH,
Vyas
http://vyaskn.tripod.com
Go to Top of Page

VyasKN
SQL Server MVP & SQLTeam MVY

313 Posts

Posted - 2002-05-18 : 19:17:47
That's a good one Rob.

--
HTH,
Vyas
http://vyaskn.tripod.com
Go to Top of Page
   

- Advertisement -