sql-server add tag
james (imported from SE)
I've started a new job and it involves looking at a bunch of big numbers. Is there an easy way to add commas to an `int` or `decimal` field to make it readable?

For example, SQL Server outputs the column on the left, but for my own sanity, I need it to look like the one on the right:

    2036150 -> 2,036,150  

...or would I have to write some heinous 

    left(right(vandalized_data),6),3) + ',' + right(left(vandalized_data),6),3)

function?

The perfect thing would be commas in the display grid, then plain integers in the output.
Top Answer
meme (imported from SE)
If you're on SQL Server 2012+, and you want to do it (without decimal places):

    SELECT FORMAT(2036150, N'N0')

If you're on an earlier version, you have to jump through some hoops:

    SELECT REPLACE(CONVERT(NVARCHAR(30), CAST((2036150) AS MONEY), 1), N'.00', N'')

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.