Ask Your Question
1

How can decimal places be formatted with commas in SQL Server?

asked 2023-06-07 22:22:45 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-07 22:51:01 +0000

djk gravatar image

In SQL Server, the FORMAT function can be used to format decimal places with commas. The syntax is as follows:

FORMAT (value, 'format')

The 'value' parameter is the decimal value you want to format with commas, and the 'format' parameter specifies the format in which you want to display the decimal value. For example, to format a decimal value with two decimal places and commas, you can use the following code:

SELECT FORMAT(1234567.89, 'N2')

This will return the value '1,234,567.89'.

Alternatively, you can use the CONVERT function to format decimal values with commas as follows:

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

This will also return the value '1,234,567.89'. The '1' parameter in the CONVERT function specifies the format style.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-07 22:22:45 +0000

Seen: 14 times

Last updated: Jun 07 '23