How to put commas for every 3 digit in SQL?

Viewed 99

I'm new to SQL and stack overflow, I wanted to ask, how to put commas after 3 number?

The result I get is 150444600000.0, what I wanted is 150,444,600,000.0 so I can read the number easier.

Below attached the image syntax for reference

image here

3 Answers

You can do it with the function printf():

SELECT printf('%,d.%01d', SUM(total_revenue * 30)) AS total_monthly_revenue

There is no need to cast to float.

See the demo.

Please try this syntax

SELECT FORMAT(150444600000.0, 'C4')

Output


$150,444,600,000.0000

For more information check this link: SQL Server Formats

SELECT FORMAT(12134567.829, '#,#.00')

enter image description here

Related