Thankfully(?), in SQL Server 2012+, you can now use FORMAT() to achieve this:

FORMAT(@s,'#,0.0000')


In prior versions, at the risk of looking real ugly

[Query]:

declare @s decimal(18,10);
set @s = 1234.1234567;
select replace(convert(varchar,cast(floor(@s) as money),1),'.00',
    '.'+right(cast(@s * 10000 +10000.5 as int),4))

In the first part, we use MONEY->VARCHAR to produce the commas, but FLOOR() is used to ensure the decimals go to .00. This is easily identifiable and replaced with the 4 digits after the decimal place using a mixture of shifting (*10000) and CAST as INT (truncation) to derive the digits.

[Results]:

|   COLUMN_0 |
--------------
| 1,234.1235 |

But unless you have to deliver business reports using SQL Server Management Studio or SQLCMD, this is NEVER the correct solution, even if it can be done. Any front-end or reporting environment has proper functions to handle display formatting.

Answer from RichardTheKiwi on Stack Overflow
Top answer
1 of 5
40

Thankfully(?), in SQL Server 2012+, you can now use FORMAT() to achieve this:

FORMAT(@s,'#,0.0000')


In prior versions, at the risk of looking real ugly

[Query]:

declare @s decimal(18,10);
set @s = 1234.1234567;
select replace(convert(varchar,cast(floor(@s) as money),1),'.00',
    '.'+right(cast(@s * 10000 +10000.5 as int),4))

In the first part, we use MONEY->VARCHAR to produce the commas, but FLOOR() is used to ensure the decimals go to .00. This is easily identifiable and replaced with the 4 digits after the decimal place using a mixture of shifting (*10000) and CAST as INT (truncation) to derive the digits.

[Results]:

|   COLUMN_0 |
--------------
| 1,234.1235 |

But unless you have to deliver business reports using SQL Server Management Studio or SQLCMD, this is NEVER the correct solution, even if it can be done. Any front-end or reporting environment has proper functions to handle display formatting.

2 of 5
15

without considering this to be a good idea...

select dbo.F_AddThousandSeparators(convert(varchar, convert(decimal(18, 4), 1234.1234567), 1))

Function

-- Author:      bummi
-- Create date: 20121106
CREATE FUNCTION F_AddThousandSeparators(@NumStr varchar(50)) 
RETURNS Varchar(50)
AS
BEGIN
declare @OutStr varchar(50)
declare @i int
declare @run int

Select @i=CHARINDEX('.',@NumStr)
if @i=0 
    begin
    set @i=LEN(@NumStr)
    Set @Outstr=''
    end
else
    begin   
     Set @Outstr=SUBSTRING(@NUmStr,@i,50)
     Set @i=@i -1
    end 


Set @run=0

While @i>0
    begin
      if @Run=3
        begin
          Set @Outstr=','+@Outstr
          Set @run=0
        end
      Set @Outstr=SUBSTRING(@NumStr,@i,1) +@Outstr  
      Set @i=@i-1
      Set @run=@run + 1     
    end

    RETURN @OutStr

END
GO
🌐
Experts Exchange
experts-exchange.com › questions › 29161664 › MS-SQL-Server-using-decimal-comma.html
Solved: MS SQL Server - using decimal comma | Experts Exchange
October 21, 2019 - I am hoping that there is a locale setting that tells SQL server to use decimal comma and not decimal point. And this setting should only apply in the current session i.e. in the stored procedure. ... We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads. ... Just use FORMAT() and specify an according culture (en-US, de-DE).
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › functions › format-transact-sql
FORMAT (Transact-SQL) - SQL Server | Microsoft Learn
The following example shows how to format large numbers with comma separators. SELECT FORMAT(1234567.89, 'N0') AS FormattedNumber; Here's the result set. ... This example uses the N format specifier. The N specifier is used for numeric values, and the number of decimal places can be adjusted by changing the format string (for example, N2 for two decimal places).
Top answer
1 of 3
15

(If you are using SQL Server 2012 or newer, please see @wBob's answer for a cleaner approach. The approach outlined in my answer below is only required if you are using SQL Server 2008 R2 or older.)

You don't need (or want) the thousands' separator when converting to NUMERIC, regardless if it is comma, period, or space, so just get rid of them first. Then convert the comma into a period / decimal and you are done:

SELECT CONVERT(NUMERIC(10, 2), 
               REPLACE(
                       REPLACE('7.000,45', '.', ''),
                       ',', '.'
                      )
              ) AS [Converted];

Returns:

7000.45

For the sake of completeness, I should mention that I also tried:

  • SET LANGUAGE Greek;

  • Looking at various format styles for CONVERT, but nothing applies here.

  • The FORMAT function, but the input type must be a numeric or date/time/datetime value (that and it was introduced in SQL Server 2012, so not applicable to SQL Server 2008 R2 or older).

And nothing else seemed to work. I was hoping to find something more elegant than two REPLACE calls, but so far no such luck.


Also, just to mention, while not a pure T-SQL solution, this can also be accomplished via SQLCLR. And, there is a pre-done function that does this in the SQL# library (that I wrote) named String_TryParseToDecimal. This function is available in the Free version, and works in every version of SQL Server starting with SQL Server 2005:

SELECT SQL#.String_TryParseToDecimal('7.000,45', 'el-GR');

Returns:

7000.45000000000000000000
2 of 3
14

What version of SQL Server are you using? From SQL Server 2012 onwards you can use TRY_PARSE with its USING culture argument. You can also use PARSE, the difference being PARSE will fail if the conversion fails and TRY_PARSE will return a NULL, eg

DECLARE @t TABLE ( x VARCHAR(10) )

INSERT INTO @t
VALUES ( '7.000,45' ), ( 'xxx' )

SELECT x, 
    TRY_PARSE( x AS NUMERIC(10,2) USING 'El-GR' ) x
FROM @t

HTH

🌐
DataCamp
datacamp.com › doc › mysql › mysql-format
MySQL FORMAT Expressions: Usage & Examples
The `FORMAT` expression in MySQL is used to format numbers to a specified number of decimal places, adding commas as thousands separators. It is particularly useful for enhancing the readability of numerical data in SQL queries.
🌐
SQLServerCentral
sqlservercentral.com › forums › topic › select-convert-to-2-decimal-places-comma-right-aligned
Select convert to 2 decimal places, comma, right aligned – SQLServerCentral Forums
May 29, 2014 - NOTE: Due to the use of two REVERSE functions and the FORMAT function, this is not recommended for use on queries that will produce a large number of rows. I'm personally using this for a query that outputs a small number of rows (<5000 rows) so for me, the performance hit is not a problem. I'm adding commas using the FORMAT() function, reversing it, then converting to a CHAR(10) to pad spaces, then reversing again.
🌐
SQLServerCentral
sqlservercentral.com › forums › topic › formatting-numbers-commas-and-decimal
Formatting numbers (commas and decimal) – SQLServerCentral Forums
September 22, 2007 - -- Frank Kalis Microsoft SQL Server MVP Webmaster: http://www.insidesql.org/blogs My blog: http://www.insidesql.org/blogs/frankkalis/[/url] ... SSC Eights! ... After confirming what Frank says about 'resentation issue...' I just add that sometimes a 'vb format in tsql' can be usefule... ... Peter E. Kierstead ... I use this quick and dirty function (emphasis on adjectives) for integer and decimal values.
🌐
Database Guide
database.guide › how-to-format-numbers-with-commas-in-sql
How to Format Numbers with Commas in SQL
December 13, 2021 - In MySQL, we can use the FORMAT() function to format numbers with commas: ... There’s no need to specify where the commas should go. The function knows where to put them. This function also accepts a third argument to specify the locale. Not all locales use a comma as the group separator ...
🌐
Database Guide
database.guide › how-to-format-numbers-with-commas-in-sql-server
How to Format Numbers with Commas in SQL Server
October 27, 2021 - It’s also possible to use custom format specifiers to construct your own custom format strings. For example, the # character is a digit placeholder, the 0 is a zero placeholder, the comma (,) is a placeholder for the group separator, and the full stop (.) is a placeholder for the decimal ...
Find elsewhere
🌐
MSSQLTips
mssqltips.com › home › sql format number with cast, convert and more
SQL Format Number with CAST, CONVERT and more
October 31, 2025 - CONVERT is also particularly useful for parsing and formatting VARCHAR into date and time. More examples are available in this document. Similarly to TRY_CAST, we also have TRY_CONVERT which also returns NULL in case the conversion fails. The syntax is identical to the original function. SELECT CONVERT(int, 'maybe int') as int_ GO SELECT TRY_CONVERT(int, 'maybe int') as try_convert_int GO · The SQL ROUND function may be useful if you want to round the number of decimal places.
🌐
Actian
docs.actian.com › psql › psqlv13 › sqlref › sqlref.SET_DECIMALSEPARATORCOMMA.htm
SET DECIMALSEPARATORCOMMA
The PSQL database engine by default displays decimal data using a period (.) as the separator between ones and tenths (for example, 100.95). The SET DECIMALSEPARATORCOMMA statement allows you to specify that results should be displayed using a comma to separate ones and tenths (for example, 100,95).
🌐
Boyum Help Center
support.boyum-it.com › hc › en-us › articles › 4410540556561-How-to-work-with-decimal-format-in-SQL-Set-command-if-comma-is-used-as-decimal-separator
How to work with decimal format in SQL: Set command if comma is used as decimal separator – Boyum Help Center
November 10, 2021 - In this example, the bolded part can be any calculation or decimal value: So instead of using SQL: Set($[$29.0.0]|SQL:SELECT 1.15); You can use SQL_INVARIANT: Set($[$29.0.0]|SQL_INVARIANT:SELECT 1.15) SQL invariant is used to ensure that decimal numbers are returned in the correct format depending on your system and region. You can see more info in the manual: https://manual.boyum-it.com/B1UP/index.html?command-set.html
🌐
Sqlmatters
sqlmatters.com › Articles › Formatting a number with thousand separators.aspx
Formatting a number with thousand separators - SQLMatters
Post by Darren on Mon 03 Dec 2018 16:19. Report Inappropriate Post Website : Another way to get commas, which is easier (for me) to remember: SELECT FORMAT(123456789, 'N0') --that's a zero, specifying the number of decimal places Result: 123,456,789
🌐
My Tec Bits
mytecbits.com › home › microsoft › sql server › how to format a number with commas in sql server?
How to format a number with commas in SQL Server? | My Tec Bits
October 18, 2023 - ... If you are using an SQL Server version older than 2012, then you will not have the option to use FORMAT. The easiest way to format the number with commas without the FORMAT function is by using the CONVERT and CAST functions.
🌐
Microsoft
social.msdn.microsoft.com › Forums › sqlserver › en-US › 3846daba-91d4-42e1-9f64-68015633fa39 › format-number-with-comma-and-1-decimal-point
Format number with comma and 1 decimal point | Microsoft Learn
February 9, 2022 - SELECT ROUND(1234.56, 1, 1) , CAST(ROUND(1234.56, 1, 1) AS decimal(5,1)) If your problem is with the formatting, to get the "," and "." in the right places, then please show the code that currently formats the number. ... Please, please, please read any book on RDBMS and modern programming! We use tiered architectures like SQL's Client/Server.Display formatting is always done in a presentation layer and never, never in the database.
🌐
SQL Server Guides
sqlserverguides.com › format-number-with-commas-and-decimal-in-sql-server
How to Format Number with Commas and Decimal in SQL Server? - SQL Server Guides
November 6, 2023 - In the query part FORMAT(SalePrice,’ N3′), the N3 is the format specified or pattern that is applied to the SalePrice column,. N3 means add the thousand separators (commas) and displaying three decimal places for the number within the SalePrice column. If you use the format pattern as N2 in the FORMAT() function, then it displays the number value with two decimal places with a thousand separators. So here, the number (2, 3, etc.) after the N represents the number of digits you want to put after the decimal in any numeric value. You can also provide a custom format pattern to the FORMAT() function in SQL Server.