Wednesday, August 18, 2010

T-SQL Formatting Number with Commas

I don't know about you, but I find reading very large numbers difficult without a commas.  Often, when I'm looking at performance statistics in SQL Server I want to see the output including commas for the sake of my feeble brain.  SQL Server most likely lacks this functionality natively because formatting really belongs on a presentation layer.  However, since most of my work is in SQL Management Studio, I choose to do the following:

CONVERT(varchar, CAST(<column name> AS money), 1)

I realize it's a simple, un-elegant and totally duct-tape programmer approach to solving this problem.  However, someone else might benefit from it as I do so I choose to share it.

If you want to save some typing, you can always create it as a function that might look like this:

No comments:

Post a Comment