Format a number with commas but without decimals in SQL Server 2008 R2?

后端 未结 5 988
情歌与酒
情歌与酒 2020-12-10 16:06

I am using the following to create a comma formatted number in T-SQL. How can I get rid of the decimal point and the digits after decimal. So if I get 1,112.00 after formatt

5条回答
  •  感动是毒
    2020-12-10 16:23

    Like so:

    SELECT REPLACE(CONVERT(VARCHAR(20), CAST(1112 AS MONEY), 1), '.00', '');
    

    This will always work fine. Since CONVERT(VARCHAR(20), CAST(1112 AS MONEY), 1) will always return a number with .00. However, the MitchWheat's answer is better in case there is a number with decimal numbers after the comma.

    Note that: You should consider to do this formatting stuff in the front end application. T-SQL is not about formatting.

提交回复
热议问题