SQL Server 2008 thousands separator for a column

2019-01-18 10:19发布

问题:

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!

回答1:

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


回答2:

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



回答3:

Formatting numbers for display is something that should be done in the display layer, and not within the database. So, in whatever application this data ends up being used, you should format it there. Management Studio, unfortunately, does not offer much control in this regard.



回答4:

use this simple.... format(CHART_OF_ITEM.UNIT_PRIC_W_TAX, '#,0.00') AS UNIT_PRICE_W_TAX



回答5:

Try this One awesome example.

SELECT CAST(CONVERT(varchar, CAST(123456 AS money), 1) AS varchar)