Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2008 thousands separator for a column

I have a column called TotalArea and its format is numeric (12,2).

I want it to display the numbers with a thousand separator so when I

select TotalArea from table 

to show me a format like 1,234.00.

How could I do that? Thanks!

like image 939
user1820705 Avatar asked Dec 13 '12 10:12

user1820705


People also ask

How do I change the decimal separator in SQL Server?

SQL Fiddle Demo You can first replace thousand separator comma(,) to a Zero length string (''), and then you can replace Decimal('. ') to comma(',') in the same select statement.

How can use comma separator in SQL Server?

In order to fetch the comma separated (delimited) values from the Stored Procedure, you need to make use of a variable with data type and size same as the Output parameter and pass it as Output parameter using OUTPUT keyword.

How do I add a comma to a string in SQL?

You can use backslash(\) to insert commas into values.


2 Answers

Try this way:

SELECT REPLACE(CONVERT(VARCHAR, CONVERT(MONEY, TotalArea), 1), '.00', '')  FROM table 

or

SELECT CAST(CONVERT(VARCHAR, CAST(123456 AS MONEY), 1) AS VARCHAR) FROM table 
like image 193
Robert Avatar answered Oct 11 '22 23:10

Robert


SELECT FORMAT(12345,'#,0.00');  SELECT FORMAT(TotalArea,'#,0.00') from table; 

Reference: https://msdn.microsoft.com/en-us/library/ee634206(v=sql.105).aspx

like image 25
dasiimwe Avatar answered Oct 11 '22 23:10

dasiimwe