﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Jesse McLain  / Insert Commas Into Number String / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 21 May 2013 14:33:55 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Insert Commas Into Number String</title><link>http://www.sqlservercentral.com/Forums/Topic687713-1181-1.aspx</link><description>Hi Ryan,One observation - it doesn't handle negative values.This fixes that problem, but at the expense of some readability:SELECT REPLACE(CONVERT(varchar(24), floor(abs(CONVERT(money, @s))) * sign(convert(money, @s)), 1), '.00', substring(@s, charindex('.', @s + '.'), 20))There may be a more elegant fix than this.CheersJohn</description><pubDate>Fri, 30 Oct 2009 05:55:46 GMT</pubDate><dc:creator>jdarsley</dc:creator></item><item><title>RE: Insert Commas Into Number String</title><link>http://www.sqlservercentral.com/Forums/Topic687713-1181-1.aspx</link><description>[quote][b]unladenswallow (4/28/2009)[/b][hr]If it's important to leave the decimal part alone, it's easy to just do this to the characters to the left of the decimal point in the original string, and then replace the '.00' with the original decimal value, if any.[/quote]I couldn't resist doing it. Can this be improved?[code]--inputsdeclare @s varchar(20)--set @s = '12345.6789'--set @s = '1234567'set @s = '123456789.01234567'--/--calculationSELECT REPLACE(CONVERT(varchar(24), FLOOR(CONVERT(money, @s)),1), '.00', substring(@s, charindex('.', @s + '.'), 20))--//*outputs12,345.67891,234,567123,456,789.01234567*/[/code]</description><pubDate>Wed, 29 Apr 2009 03:21:03 GMT</pubDate><dc:creator>RyanRandall</dc:creator></item><item><title>RE: Insert Commas Into Number String</title><link>http://www.sqlservercentral.com/Forums/Topic687713-1181-1.aspx</link><description>From what I remember, this code should also insert the appropriate commas, but then also get the number up to the decimal (after rounding). select Substring (CONVERT(varchar(25),round(cast('12345678.99' as money),0),1) ,1,patindex( '%.%',CONVERT(varchar(25),round(cast('12345678.99' as money),0),1)) -1)</description><pubDate>Tue, 28 Apr 2009 07:47:53 GMT</pubDate><dc:creator>T C</dc:creator></item><item><title>RE: Insert Commas Into Number String</title><link>http://www.sqlservercentral.com/Forums/Topic687713-1181-1.aspx</link><description>Nice trick, swallow!African or European?</description><pubDate>Tue, 28 Apr 2009 06:05:43 GMT</pubDate><dc:creator>jcrawf02</dc:creator></item><item><title>RE: Insert Commas Into Number String</title><link>http://www.sqlservercentral.com/Forums/Topic687713-1181-1.aspx</link><description>If two decimal places are ok, you can just convert the string to money, then back to a string with a style of 1.SELECT CONVERT(varchar(24),CONVERT(money,'12345678'),1)returns:  12,345,678.00If it's important to leave the decimal part alone, it's easy to just do this to the characters to the left of the decimal point in the original string, and then replace the '.00' with the original decimal value, if any.</description><pubDate>Tue, 28 Apr 2009 01:02:51 GMT</pubDate><dc:creator>unladenswallow</dc:creator></item><item><title>Insert Commas Into Number String</title><link>http://www.sqlservercentral.com/Forums/Topic687713-1181-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/TSQL/66428/"&gt;Insert Commas Into Number String&lt;/A&gt;[/B]</description><pubDate>Wed, 01 Apr 2009 03:06:41 GMT</pubDate><dc:creator>Jesse McLain</dc:creator></item></channel></rss>