Langsung ke konten utama

Format Number With Commas in Sql Server

In SQL Server 2012 and higher, this will format a number with commas:
SELECT FORMAT([Number], 'N0')
You can also change 0 to the number of decimal places you want.



Demo 1
Demonstrates adding commas:
SELECT FORMAT(5000000, '#,##0')
Result
5,000,000

Demo 2
Demonstrates commas and decimal points. Observe that it rounds the last digit if necessary.
SELECT FORMAT(5000000.759145678, '#,##0.00')
Result
5,000,000.76

Compatibility
SQL Server 2012+

Komentar

Postingan populer dari blog ini

sys.processes Status sp_who2 SQL Server

Taken from the books online reference for sys.processes  and the status column. dormant = SQL Server is resetting the session. running = The session is running one or more batches. When Multiple Active Result Sets (MARS) is enabled, a session can run multiple batches. For more information, see Using Multiple Active Result Sets (MARS). background = The session is running a background task, such as deadlock detection. rollback = The session has a transaction rollback in process. pending = The session is waiting for a worker thread to become available. runnable = The task in the session is in the runnable queue of a scheduler while waiting to get a time quantum. spinloop = The task in the session is waiting for a spinlock to become free. suspended = The session is waiting for an event, such as I/O, to complete.