<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Convert table to CSV string in SQL Server</title>
	<atom:link href="http://chrisfulstow.com/convert-table-to-csv-string-in-sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisfulstow.com/convert-table-to-csv-string-in-sql-server/</link>
	<description>ASP.NET Tech Lead and Web Developer</description>
	<lastBuildDate>Thu, 17 Jun 2010 12:19:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: kuba</title>
		<link>http://chrisfulstow.com/convert-table-to-csv-string-in-sql-server/comment-page-1/#comment-61</link>
		<dc:creator>kuba</dc:creator>
		<pubDate>Wed, 30 Dec 2009 08:54:40 +0000</pubDate>
		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/08/22/convert-table-to-csv-string-in-sql-server/#comment-61</guid>
		<description>COALESCE(Name, ”) return Name or empty string  if Name is null. check http://msdn.microsoft.com/en-us/library/ms190349.aspx</description>
		<content:encoded><![CDATA[<p>COALESCE(Name, ”) return Name or empty string  if Name is null. check <a href="http://msdn.microsoft.com/en-us/library/ms190349.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms190349.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ME</title>
		<link>http://chrisfulstow.com/convert-table-to-csv-string-in-sql-server/comment-page-1/#comment-59</link>
		<dc:creator>ME</dc:creator>
		<pubDate>Fri, 13 Nov 2009 14:33:02 +0000</pubDate>
		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/08/22/convert-table-to-csv-string-in-sql-server/#comment-59</guid>
		<description>What if the list has null value?</description>
		<content:encoded><![CDATA[<p>What if the list has null value?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gordon</title>
		<link>http://chrisfulstow.com/convert-table-to-csv-string-in-sql-server/comment-page-1/#comment-58</link>
		<dc:creator>Gordon</dc:creator>
		<pubDate>Fri, 06 Nov 2009 15:53:19 +0000</pubDate>
		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/08/22/convert-table-to-csv-string-in-sql-server/#comment-58</guid>
		<description>Here&#039;s a faster variant of the code you gave:

DECLARE @Csv NVARCHAR(MAX)
SET @Csv = &#039;&#039;
SELECT @Csv = @Csv + COALESCE(Name, &#039;&#039;) + &#039;,&#039;
FROM Animals
SET @Csv = SUBSTRING(@Csv 1, LEN(@Csv) - 1)
SELECT @Csv

...and another even faster, albeit hacky variant:
DECLARE @Csv NVARCHAR(MAX)
SELECT @Csv =
(
	SELECT COALESCE(Name, &#039;&#039;) + &#039;,&#039;
	FROM Animal
	FOR XML PATH(&#039;&#039;)
)
SET @Csv = SUBSTRING(@Csv, 1, LEN(@Csv) - 1)
SELECT @Csv

(I&#039;m using SQL Server 2005)</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a faster variant of the code you gave:</p>
<p>DECLARE @Csv NVARCHAR(MAX)<br />
SET @Csv = &#8221;<br />
SELECT @Csv = @Csv + COALESCE(Name, &#8221;) + &#8216;,&#8217;<br />
FROM Animals<br />
SET @Csv = SUBSTRING(@Csv 1, LEN(@Csv) &#8211; 1)<br />
SELECT @Csv</p>
<p>&#8230;and another even faster, albeit hacky variant:<br />
DECLARE @Csv NVARCHAR(MAX)<br />
SELECT @Csv =<br />
(<br />
	SELECT COALESCE(Name, &#8221;) + &#8216;,&#8217;<br />
	FROM Animal<br />
	FOR XML PATH(&#8221;)<br />
)<br />
SET @Csv = SUBSTRING(@Csv, 1, LEN(@Csv) &#8211; 1)<br />
SELECT @Csv</p>
<p>(I&#8217;m using SQL Server 2005)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle</title>
		<link>http://chrisfulstow.com/convert-table-to-csv-string-in-sql-server/comment-page-1/#comment-57</link>
		<dc:creator>Kyle</dc:creator>
		<pubDate>Thu, 22 Oct 2009 22:39:54 +0000</pubDate>
		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/08/22/convert-table-to-csv-string-in-sql-server/#comment-57</guid>
		<description>SUUUUPER  handy, I never would have thought of that. Thanks a lot.

Amanda: I too need a list of ints so I&#039;ve modified it a bit to turn the ints into strings
select @csv = coalesce(@csv + &#039;, &#039;, &#039;&#039;) + LTRIM(STR(AnimalID)) from Animals</description>
		<content:encoded><![CDATA[<p>SUUUUPER  handy, I never would have thought of that. Thanks a lot.</p>
<p>Amanda: I too need a list of ints so I&#8217;ve modified it a bit to turn the ints into strings<br />
select @csv = coalesce(@csv + &#8216;, &#8216;, &#8221;) + LTRIM(STR(AnimalID)) from Animals</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amanda</title>
		<link>http://chrisfulstow.com/convert-table-to-csv-string-in-sql-server/comment-page-1/#comment-56</link>
		<dc:creator>Amanda</dc:creator>
		<pubDate>Thu, 15 Oct 2009 00:53:09 +0000</pubDate>
		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/08/22/convert-table-to-csv-string-in-sql-server/#comment-56</guid>
		<description>I could only create a list of varchar elements, what about a list of int?</description>
		<content:encoded><![CDATA[<p>I could only create a list of varchar elements, what about a list of int?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nbnew25</title>
		<link>http://chrisfulstow.com/convert-table-to-csv-string-in-sql-server/comment-page-1/#comment-55</link>
		<dc:creator>nbnew25</dc:creator>
		<pubDate>Wed, 14 Oct 2009 04:27:51 +0000</pubDate>
		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/08/22/convert-table-to-csv-string-in-sql-server/#comment-55</guid>
		<description>Thank you very much.
It very good ^^</description>
		<content:encoded><![CDATA[<p>Thank you very much.<br />
It very good ^^</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: waqar mir</title>
		<link>http://chrisfulstow.com/convert-table-to-csv-string-in-sql-server/comment-page-1/#comment-54</link>
		<dc:creator>waqar mir</dc:creator>
		<pubDate>Thu, 10 Sep 2009 03:29:26 +0000</pubDate>
		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/08/22/convert-table-to-csv-string-in-sql-server/#comment-54</guid>
		<description>wow ... i was  looking for this  ....:)
thanks</description>
		<content:encoded><![CDATA[<p>wow &#8230; i was  looking for this  &#8230;.:)<br />
thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Facundo Báez</title>
		<link>http://chrisfulstow.com/convert-table-to-csv-string-in-sql-server/comment-page-1/#comment-53</link>
		<dc:creator>Facundo Báez</dc:creator>
		<pubDate>Tue, 01 Sep 2009 15:22:11 +0000</pubDate>
		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/08/22/convert-table-to-csv-string-in-sql-server/#comment-53</guid>
		<description>Good Post! Thanks</description>
		<content:encoded><![CDATA[<p>Good Post! Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jayasabari</title>
		<link>http://chrisfulstow.com/convert-table-to-csv-string-in-sql-server/comment-page-1/#comment-52</link>
		<dc:creator>Jayasabari</dc:creator>
		<pubDate>Fri, 20 Mar 2009 04:33:33 +0000</pubDate>
		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/08/22/convert-table-to-csv-string-in-sql-server/#comment-52</guid>
		<description>Ya it&#039;s working.......

Thanks</description>
		<content:encoded><![CDATA[<p>Ya it&#8217;s working&#8230;&#8230;.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Paulsen</title>
		<link>http://chrisfulstow.com/convert-table-to-csv-string-in-sql-server/comment-page-1/#comment-51</link>
		<dc:creator>Mark Paulsen</dc:creator>
		<pubDate>Fri, 13 Mar 2009 22:33:03 +0000</pubDate>
		<guid isPermaLink="false">http://3poundmass.wordpress.com/2007/08/22/convert-table-to-csv-string-in-sql-server/#comment-51</guid>
		<description>Thank you very much for your post!  This is a very clean way to convert the data in a table column into a single string.

For others reviewing this post, note that the string being appended to @csv above -&gt;   &#039;, &#039;, &#039;&#039;   is:
1) a single quote
2) a comma
3) a space
4) a single quote
5) a comma
6) a space
7) two single quotes

NOTE: single quotes are used to delimit strings in SQL</description>
		<content:encoded><![CDATA[<p>Thank you very much for your post!  This is a very clean way to convert the data in a table column into a single string.</p>
<p>For others reviewing this post, note that the string being appended to @csv above -&gt;   &#8216;, &#8216;, &#8221;   is:<br />
1) a single quote<br />
2) a comma<br />
3) a space<br />
4) a single quote<br />
5) a comma<br />
6) a space<br />
7) two single quotes</p>
<p>NOTE: single quotes are used to delimit strings in SQL</p>
]]></content:encoded>
	</item>
</channel>
</rss>
