Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a select statement output a number with commas

Tags:

sql

sql-server

I am using SQL Server and am trying to figure out how to make a select statement output a number separated by commas. I am only able to find how to transform a number into a number with commas, which isn't what I want. The following code is the code I am trying to get to output as a number with commas. Right now when you execute the statement it returns a value of 750000.00 and I want it to return 750,000.00.

Code:

select max(c.salary) as MaxSalary
from #Career c inner join
     #Member m
    on c.Member_ID = m.Member_ID
where m.age < 35

1 Answers

You can use FORMAT() for SQL Server 2012 onward

select FORMAT(750000.00, 'N', 'en-us') AS 'Numeric Format' 


declare @table table(salary decimal(16,4))
insert into @table
values
(1234.00),
(64423.55)

select FORMAT(sum(salary), 'N', 'en-us') AS 'Numeric Format' 
from @table

--or using your tables
select FORMAT(max(c.salary), 'N', 'en-us') AS 'Numeric Format' 
from #Career c inner join
     #Member m
    on c.Member_ID = m.Member_ID
where m.age < 35
like image 170
S3S Avatar answered Nov 27 '25 01:11

S3S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!