Total PageViews

Tuesday, April 27, 2021

How to add thousand’s separator in SQL server database for numeric value

Suppose we have a column in a table in which we are storing some numeric value and at the time of showing the data in a report or in any platform that we need to show that numeric value with a thousand's separator.

Query:-

Declare @V_ColumnName int

Set @V_ColumnName=1234567890

Print @V_ColumnName

O/P:- 1234567890

In the above block, we have declared one variable i.e @V_ColumnName and in that, we are storing some dummy value and when we execute this block will get the output without thousand’s separator. To show the value in output with thousand’s separator then

Query:-

Declare @V_ColumnName int

Set @V_ColumnName=1234567890

Select CONVERT(VARCHAR, CONVERT(MONEY, @V_ColumnName), 1) as ThousandsValue

 

O/P:- 1,234,567,890.00

As we are adding the comma in between the value that's why we have converted the value to varchar.


What other ideas can you add to this post that I may have not mentioned?