Displaying thousand seperators in SQL numbers

If you want to display a number 999999999.99 as 999,999,999.99 then it’s normally best to do this in the front end application but if you must do it in sql the way to do it is with the money type.

You simply store your data as money or convert it to money on the fly using convert. Then wrap the value in a convert to varchar with a style of 1

e.g.

DECLARE @MoneyValue float = 999999999999.99
select CONVERT (varchar, CONVERT(money,@MoneyValue ) ,1)

Advertisements

About davidbridge

I am a contractor for David Bridge Technology Limited specialising in database design and Web development using Microsoft technologies such as c#, MVC .net and SQL Server (full stack)
This entry was posted in Developer stuff, SQL Stuff and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s