Tuesday, September 17, 2013

Convert VARCHAR value to decimal value with thousand separator in SQL Server

This is really easy to do in following way. Have a look on below snippets:
DECLARE @NumberValue varchar(100)
SET @NumberValue = '1234567891234.45'

SELECT CONVERT(VARCHAR,CONVERT(MONEY,@NumberValue),1)

Result:  1,234,567,891,234.45

If you need to add any decimal places, just use following snippet to handle it.
DECLARE @NumberValue varchar(100)
SET @NumberValue = '1234567891234'

SELECT CONVERT(VARCHAR,CONVERT(MONEY,@NumberValue),1)

Result:  1,234,567,891,234.00

No comments:

Post a Comment