Search code examples
sql-servercurrencycurrency-formatting

Sql Server select money with comma


I have Payment table in ms sql server.

Payment table has below column type of money

Salary 

Salary column has below values

1495.88

2235.08

719.59

15.75

9.59

0.00

NULL

97.77

When i select query as below,

select Salary from Payment where 

Result must be below

1,495,88

2,235,08

719,59

15,75

9,59

0,00

NULL

97,77

I tried below

SELECT CONVERT(varchar, CAST(Salary AS money), 1) from  Payment 

this did not work for me.

How can i get money as comma format

thanks


Solution

  • Let your client app to format result, but if you wish you can do it like :

    DECLARE @m MONEY  = 10000000.12
    SELECT CONVERT(NVARCHAR(20), @m, 1) AS Result
    

    Output:

    Result
    10,000,000.12
    

    For dot:

    DECLARE @m MONEY  = 10000000.12
    SELECT REPLACE(CONVERT(NVARCHAR(20), @m, 5), '.', ',') AS Result
    

    Output:

    Result
    10,000,000,12