<?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>Search results matching tags 'SQL Server Integration Services' and 'Sort transform'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=SQL+Server+Integration+Services,Sort+transform&amp;orTags=0</link><description>Search results matching tags 'SQL Server Integration Services' and 'Sort transform'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Sort transform arbitration [SSIS]</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2009/11/12/sort-transform-arbitration-ssis.aspx</link><pubDate>Thu, 12 Nov 2009 19:40:19 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:18793</guid><dc:creator>jamiet</dc:creator><description>&lt;p&gt;This post was prompted by a &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/581df31a-5cd0-4802-a472-7ee85c6e8464"&gt;thread&lt;/a&gt; on the &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/threads"&gt;MSDN SSIS forum&lt;/a&gt; today where the poster was asking how he could replicate the behaviour of SSIS’s Sort transform using T-SQL, specifically he wanted to know how the Sort transform chooses what data to pass through when the “Remove Duplicates” option is checked.&lt;/p&gt;  &lt;p&gt;Let me give a bit more background. Take the following dataset:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_3698AD62.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_05D57FEA.png" width="152" height="152" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Note how we have repeated values (‘Simon’ &amp;amp; ‘Louis’) in the [Mentor] column. &lt;/p&gt;  &lt;p&gt;Now let’s pass that data through SSIS’s Sort transform which we will sort on [Mentor] and choose to “Remove rows with duplicate sort values”:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_4FF08ACF.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_1B038592.png" width="560" height="484" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Notice how [Mentee] is a Pass Through column.&lt;/p&gt;  &lt;p&gt;When we execute this then we get the following output from the Sort Transform:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_2F592550.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_62B4E8AC.png" width="324" height="224" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Notice anything? Two of our [Mentee] values have disappeared, namely ‘Jedward’ and ‘Danyl’. The Sort Transform has removed duplicates from [Mentor] and arbitrarily picked which value it should pass through for [Mentee].&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Speaking personally I see no value at all in this arbitrary behaviour. Let me clarify that statement, the ability to remove duplicates is very very valuable but the practise of passing through an arbitrary value along with the de-duplicated values is pointless. The poster on the forum was asking how he could replicate this behaviour in T-SQL and I had to tell him (a) You can’t, because we don’t know what algorithm the Sort transform is using to choose its arbitrary value and (b) why would you even want to? I don’t know of any business rule that would value being able to say “Just give me any value back, I don’t care which”.&lt;/p&gt;  &lt;p&gt;In my opinion the Sort transform should remove Pass Through columns when the “Remove rows with duplicate sort values” option is checked. They are pointless and thus may be confusing for new users of the product.&lt;/p&gt;  &lt;p&gt;What do you think? Agree or disagree? Let me know in the comments!&lt;/p&gt;  &lt;p&gt;@Jamiet&lt;/p&gt;  &lt;p&gt;P.S. Apologies to the none-UK residents that are oblivious to the pop-culture references in this blog post! ;)&lt;/p&gt;</description></item></channel></rss>