<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx</link><description>After weeks of putting it off, I finally found the time and spent the last day and a half judging the Grouped String Concatenation Challenge . I would like to congratulate the winner, Peter Larsson , who submitted a great query and walks away with a shiny</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#14366</link><pubDate>Mon, 01 Jun 2009 02:14:02 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14366</guid><dc:creator>Roman Nowak</dc:creator><description>&lt;p&gt;Frankly, it's a little unclear to me why you didn't choose Leonid as winner. Logical IO is considered to be a poor metric (&lt;a rel="nofollow" target="_new" href="http://sqlblog.com/blogs/joe_chang/archive/2008/09/10/why-logical-io-is-a-poor-performance-metric.aspx"&gt;http://sqlblog.com/blogs/joe_chang/archive/2008/09/10/why-logical-io-is-a-poor-performance-metric.aspx&lt;/a&gt;). Don't you agree? After all it is Leonid solution which proved to be faster.&lt;/p&gt;
&lt;p&gt;What's more having done a qick dirty check on i7 (no HT) and Peter's solution is &amp;nbsp;about 70% slower on this config (SQL 2005) - 2:21:3906 vs 1:17:6093 - that's a huge difference; so testbed seems to have a big influance here.&lt;/p&gt;
&lt;p&gt;I hope it's not rude to have such a contrary opinion - your rules, you judge - but it just an opinion you asked for.&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#14367</link><pubDate>Mon, 01 Jun 2009 10:47:31 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14367</guid><dc:creator>Dave Ballantyne</dc:creator><description>&lt;p&gt;Not that I wish to nit pick but , how were my entries deemed to have &amp;quot;order numbers not properly sorted&amp;quot; ?. &amp;nbsp;In both I ordered by OrderId, &amp;nbsp;where as Peter's winning entry order by OrderNumber. &amp;nbsp;The end result is the same though as OrderNumber is a Computer column based upon OrderId !. &amp;nbsp;Or can you point me to a customer id where there is a different order. A quick eyeball of the top 10 rows shows no difference. &amp;nbsp;Either way quite happy with the performance of my queries though.&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#14370</link><pubDate>Mon, 01 Jun 2009 12:32:12 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14370</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Roman: Yup, my rules, my verdict. &amp;nbsp;I had to choose one, so I did, based on one of the available metrics.&lt;/p&gt;
&lt;p&gt;Dave: Yes, it's a computed column, but not explicitly sorting on the right thing seems to mess with the results. &amp;nbsp;Try running my expansion script and you can see this for yourself. &amp;nbsp;Why did you decide to sort on the ID column rather than the column you actually wanted the output sorted by?&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#14371</link><pubDate>Mon, 01 Jun 2009 14:25:24 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14371</guid><dc:creator>Alejandro Mesa</dc:creator><description>&lt;p&gt;Congrats to Peter Larsson.&lt;/p&gt;
&lt;p&gt;Thanks Adam; I enjoyed the fun.&lt;/p&gt;
&lt;p&gt;AMB&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#14372</link><pubDate>Mon, 01 Jun 2009 14:45:54 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14372</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Update on the sorting issue, which disqualified several promising entries: The problem seems to be that the SalesOrderNumber column is not padded. &amp;nbsp;It's just a concatenation of 'SO' and the number converted to NVARCHAR. &amp;nbsp;My expansion script puts a lot of new numbers into the table, so we get the following situation:&lt;/p&gt;
&lt;p&gt;SalesOrderID - Ordered&lt;/p&gt;
&lt;p&gt;234&lt;/p&gt;
&lt;p&gt;456&lt;/p&gt;
&lt;p&gt;123456&lt;/p&gt;
&lt;p&gt;SalesOrderNumber - Ordered&lt;/p&gt;
&lt;p&gt;SO123456&lt;/p&gt;
&lt;p&gt;SO234&lt;/p&gt;
&lt;p&gt;SO456&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#14376</link><pubDate>Mon, 01 Jun 2009 16:06:33 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14376</guid><dc:creator>Virgil Rucsandescu</dc:creator><description>&lt;p&gt;Hi Adam,&lt;/p&gt;
&lt;p&gt;I couldn't find my name anywhere (checked Round 1 Eliminated, Round 2 Eliminated, Round 3 Eliminated). Are you sure you considered my script? Now I don't have access to my home home Outlook, but home I should have the message I sent you...&lt;/p&gt;
&lt;p&gt;Was there any &lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#14379</link><pubDate>Mon, 01 Jun 2009 16:26:35 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14379</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi Virgil,&lt;/p&gt;
&lt;p&gt;I just checked my e-mail archive and don't see anything from you. &amp;nbsp;Are you sure you sent it? &amp;nbsp;If so, did you make sure to follow the rules exactly? &amp;nbsp;I had a SPAM exclusion for the correct subject line--if you didn't specify it properly your e-mail may have been discarded.&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#14382</link><pubDate>Mon, 01 Jun 2009 18:46:12 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14382</guid><dc:creator>Jacob Bennett</dc:creator><description>&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;I'm trying to find the error in my query that made the ProductNames not order correctly but I can't seem to find the problem. &amp;nbsp;I've compared my results to Peter's and my output matches his. &amp;nbsp;Any help would be much appreciated. &amp;nbsp;My submission is in the &amp;quot;Round1_Eliminated&amp;quot; folder in Adam attachment.&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#14389</link><pubDate>Mon, 01 Jun 2009 19:36:41 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14389</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Jacob,&lt;/p&gt;
&lt;p&gt;The problem is that you put the ORDER BY in a derived table under the FOR XML PATH, instead of incorporating it as part of the same query. TOP 100 PERCENT w/ ORDER BY is optimized out in derived tables and views so it's effectively meaningless.&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#14392</link><pubDate>Mon, 01 Jun 2009 20:54:42 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14392</guid><dc:creator>Jacob Bennett</dc:creator><description>&lt;p&gt;Ah yes, old habits die hard.&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#14394</link><pubDate>Mon, 01 Jun 2009 23:12:52 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14394</guid><dc:creator>virgilrucsandescu</dc:creator><description>&lt;p&gt;Hi Adam,&lt;/p&gt;
&lt;p&gt;I forwarded few minutes ago my initial e-mail to you: (adam) (at) (this site) - I hope this is the right address ... Could you please take a look at it - I am curious what was wrong with the message, and it would be great if you could check whenever you have a little time my script (I am not competing against anybody here, just learning). Thank you so much!&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#14555</link><pubDate>Mon, 08 Jun 2009 08:54:57 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14555</guid><dc:creator>Rick Halliday</dc:creator><description>&lt;p&gt;Adam,&lt;/p&gt;
&lt;p&gt;thanks for an interesting challenge. I look forward to reading some of the other solutions to see if there is something I didn't consider or hastily dropped.&lt;/p&gt;
&lt;p&gt;Rick&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#15003</link><pubDate>Mon, 29 Jun 2009 20:22:34 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15003</guid><dc:creator>Dean Cochrane</dc:creator><description>&lt;p&gt;Hey Adam, no complaints from this quarter. Thanks for taking the time (which was substantial, I'll bet) to do this. I'll look through the other solutions. I'm sure I'll find some interesting things in there.&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#15004</link><pubDate>Mon, 29 Jun 2009 20:30:42 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15004</guid><dc:creator>Dean Cochrane</dc:creator><description>&lt;p&gt;And hey, I don't feel so bad. Some pretty good coders went out in the first round. :)&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#15397</link><pubDate>Wed, 22 Jul 2009 02:58:05 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15397</guid><dc:creator>Jeff Moden</dc:creator><description>&lt;p&gt;Heh... I guess I'm just missing it. &amp;nbsp;Where is the code from Adam Mechanic? &amp;nbsp;;-)&lt;/p&gt;
&lt;p&gt;&amp;quot;But rather than do the work all alone and simply post my solution...&amp;quot;&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#15522</link><pubDate>Mon, 27 Jul 2009 15:04:42 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15522</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Jeff, my solutions don't add much, if anything, to the group. My fastest effort was, like everyone else's, based on FOR XML PATH(''). And although I did come up with one &amp;quot;creative&amp;quot; solution based on techniques that no one else used, it performed about as well as the other unique solutions: Dismally.&lt;/p&gt;
</description></item><item><title>A bit of self back slapping</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#16650</link><pubDate>Tue, 08 Sep 2009 09:59:44 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:16650</guid><dc:creator>SQL and the like</dc:creator><description>&lt;p&gt;Recently Adam Machanic issued a fresh SQL challenge based upon concatenating string data.&amp;amp;#160; The results&lt;/p&gt;
</description></item><item><title>re: Grouped String Concatenation: ... The Winner Is ...</title><link>http://sqlblog.com/blogs/adam_machanic/archive/2009/05/31/grouped-string-concatenation-the-winner-is.aspx#16840</link><pubDate>Thu, 17 Sep 2009 17:16:40 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:16840</guid><dc:creator>CesarF</dc:creator><description>&lt;p&gt;followed your contest and congratulate you and all coders.&lt;/p&gt;
&lt;p&gt;beside all fun i got...&lt;/p&gt;
&lt;p&gt;do you know about some function as simple as:&lt;/p&gt;
&lt;p&gt;SELECT concat(StrFld+', ') FROM Table GROUP BY KeyFld&lt;/p&gt;
&lt;p&gt;that works with SQL2k?&lt;/p&gt;
&lt;p&gt;maybe a c function or so that can be added?&lt;/p&gt;
&lt;p&gt;do you know why MS postponed for so long this EVERYDAY functionality?&lt;/p&gt;
</description></item></channel></rss>