<?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: Row Concatenation in T-SQL</title>
	<atom:link href="http://sqlfool.com/2008/11/row-concatenation-in-t-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlfool.com/2008/11/row-concatenation-in-t-sql/</link>
	<description>Adventures in SQL Tuning - a blog for the rest of us</description>
	<lastBuildDate>Tue, 07 Feb 2012 21:28:07 -0700</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Matt</title>
		<link>http://sqlfool.com/2008/11/row-concatenation-in-t-sql/comment-page-1/#comment-7161</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Mon, 12 Dec 2011 15:15:31 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=115#comment-7161</guid>
		<description>Thank you so much. I have been searching for a &quot;duckies and bunnies&quot; version of this so I could understand it.  MySQL and the GROUP_CONCAT thing is a touch easier on my head.  Much appreciated.</description>
		<content:encoded><![CDATA[<p>Thank you so much. I have been searching for a &#8220;duckies and bunnies&#8221; version of this so I could understand it.  MySQL and the GROUP_CONCAT thing is a touch easier on my head.  Much appreciated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: raymond lew</title>
		<link>http://sqlfool.com/2008/11/row-concatenation-in-t-sql/comment-page-1/#comment-320</link>
		<dc:creator>raymond lew</dc:creator>
		<pubDate>Thu, 19 Feb 2009 20:52:10 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=115#comment-320</guid>
		<description>Hello Fool,  thank you this page and the method.  I have been making good use of this until I hit some quotes.  The quotes get transformed into &quot; for me; not what I want.   I tweaked the query a bit and came up with xml path (&#039;&#039;) which deals with the quotes.

Here&#039;s my working code:
/* Create a table variable to play with */
DECLARE @myTable TABLE 
    (customerID INT, textData VARCHAR(10));
 
/* Populate some test rescords */
INSERT INTO @myTable
SELECT 1, &#039;a&quot;&quot;b&#039;&#039;c&#039; UNION All
SELECT 1, &#039;de&quot;&gt;&lt;/\f&#039; UNION All
SELECT 2, &#039;uvw&#039; UNION All
SELECT 2, &#039;xyz&#039;
 
/* Just take a look at the data
   before we format it */
--SELECT * FROM @myTable;
 
/* Let&#039;s take a look at what
   For XML Raw will return 
   for us */
SELECT textData AS &#039;X&#039;
FROM @myTable
WHERE customerID = 1
ORDER BY textData
FOR XML raw;

SELECT textData as &#039;X&#039;,textData as &#039;X&#039;
FROM @myTable
WHERE customerID = 1
ORDER BY textData
FOR XML path(&#039;&#039;);
 
/* Now consolidate the data, using
   the For XML Raw option to 
   concatenate the textData column */
SELECT customerID
        , REPLACE( REPLACE( REPLACE(
            (   SELECT textData AS &#039;X&#039;
                FROM @myTable AS a
                WHERE a.customerID = b.customerID
                ORDER BY textData
               FOR XML path(&#039;&#039;) )
                , &#039;&#039;, &#039;, &#039;)
                , &#039;&#039;, &#039;&#039;)
                , &#039;&#039;, &#039;&#039;)
               AS &#039;textData&#039;
FROM @myTable b
GROUP BY customerID;

If you run this, you&#039;ll see that &#039;&gt;&#039; and &#039;&lt;&#039; are still problems.  I suppose a couple more replaces will deal with these.  Or there may be some kind of FOR XML hack.

Anyhow, thank you very much

mondo</description>
		<content:encoded><![CDATA[<p>Hello Fool,  thank you this page and the method.  I have been making good use of this until I hit some quotes.  The quotes get transformed into &quot; for me; not what I want.   I tweaked the query a bit and came up with xml path (&#8221;) which deals with the quotes.</p>
<p>Here&#8217;s my working code:<br />
/* Create a table variable to play with */<br />
DECLARE @myTable TABLE<br />
    (customerID INT, textData VARCHAR(10));</p>
<p>/* Populate some test rescords */<br />
INSERT INTO @myTable<br />
SELECT 1, &#8216;a&#8221;"b&#8221;c&#8217; UNION All<br />
SELECT 1, &#8216;de&#8221;&gt;&lt;/\f&#8217; UNION All<br />
SELECT 2, &#8216;uvw&#8217; UNION All<br />
SELECT 2, &#8216;xyz&#8217;</p>
<p>/* Just take a look at the data<br />
   before we format it */<br />
&#8211;SELECT * FROM @myTable;</p>
<p>/* Let&#8217;s take a look at what<br />
   For XML Raw will return<br />
   for us */<br />
SELECT textData AS &#8216;X&#8217;<br />
FROM @myTable<br />
WHERE customerID = 1<br />
ORDER BY textData<br />
FOR XML raw;</p>
<p>SELECT textData as &#8216;X&#8217;,textData as &#8216;X&#8217;<br />
FROM @myTable<br />
WHERE customerID = 1<br />
ORDER BY textData<br />
FOR XML path(&#8221;);</p>
<p>/* Now consolidate the data, using<br />
   the For XML Raw option to<br />
   concatenate the textData column */<br />
SELECT customerID<br />
        , REPLACE( REPLACE( REPLACE(<br />
            (   SELECT textData AS &#8216;X&#8217;<br />
                FROM @myTable AS a<br />
                WHERE a.customerID = b.customerID<br />
                ORDER BY textData<br />
               FOR XML path(&#8221;) )<br />
                , &#8221;, &#8216;, &#8216;)<br />
                , &#8221;, &#8221;)<br />
                , &#8221;, &#8221;)<br />
               AS &#8216;textData&#8217;<br />
FROM @myTable b<br />
GROUP BY customerID;</p>
<p>If you run this, you&#8217;ll see that &#8216;&gt;&#8217; and &#8216;&lt;&#8217; are still problems.  I suppose a couple more replaces will deal with these.  Or there may be some kind of FOR XML hack.</p>
<p>Anyhow, thank you very much</p>
<p>mondo</p>
]]></content:encoded>
	</item>
</channel>
</rss>

