<?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>SQLblog.com - The SQL Server blog spot on the web</title><link>http://sqlblog.com/blogs/default.aspx</link><description>&lt;p&gt;THE SQL Server Blog Spot on the Web&lt;/p&gt;</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>MicroTraining: Executing SSIS 2012 Packages 22 May 10:00 AM EDT (Free!)</title><link>http://sqlblog.com/blogs/andy_leonard/archive/2012/05/16/microtraining-executing-ssis-2012-packages-22-may-10-00-am-edt-free.aspx</link><pubDate>Wed, 16 May 2012 12:00:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43381</guid><dc:creator>andyleonard</dc:creator><slash:comments>0</slash:comments><description>I am pleased to announce the latest (free!) Linchpin People microtraining event will be held Tuesday 22 May 2012 at 10:00 AM EDT. The topic will be Executing SSIS 2012 Packages. In this presentation, I will be demonstrating several ways to execute SSIS 2012 packages. Register here ! Interested in learning about more microtraining from Linchpin People – before anyone else? Sign up for our newsletter ! :{&amp;gt;...(&lt;a href="http://sqlblog.com/blogs/andy_leonard/archive/2012/05/16/microtraining-executing-ssis-2012-packages-22-may-10-00-am-edt-free.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43381" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/andy_leonard/archive/tags/MicroTraining/default.aspx">MicroTraining</category><category domain="http://sqlblog.com/blogs/andy_leonard/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://sqlblog.com/blogs/andy_leonard/archive/tags/SSIS+2012/default.aspx">SSIS 2012</category><category domain="http://sqlblog.com/blogs/andy_leonard/archive/tags/Training/default.aspx">Training</category></item><item><title>Book Review (Book 11) - Applied Architecture Patterns on the Microsoft Platform</title><link>http://sqlblog.com/blogs/buck_woody/archive/2012/05/15/book-review-book-11-applied-architecture-patterns-on-the-microsoft-platform.aspx</link><pubDate>Tue, 15 May 2012 16:50:34 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43364</guid><dc:creator>BuckWoody</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;This is a continuation of the books I challenged myself to read to help my career - one a month, for year. &lt;a href="http://sqlblog.com/b/buckwoody/archive/2011/06/28/book-review-programming-windows-azure-by-siriram-krishnan.aspx"&gt;&lt;span style="text-decoration:underline;"&gt;&lt;span style="color:#0066cc;"&gt;You can read my first book review here&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;, and &lt;a href="http://sqlblog.com/b/buckwoody/archive/2011/06/07/head-in-the-clouds-eyes-on-the-books.aspx" target="_blank"&gt;the entire list is here&lt;/a&gt;. The book I chose for April 2012 was: &lt;a href="http://www.amazon.com/Applied-Architecture-Patterns-Microsoft-Platform/dp/184968054X" target="_blank"&gt;Applied Architecture Patterns on the Microsoft Platform&lt;/a&gt;. I was traveling at the end of last month so I&amp;rsquo;m a bit late posting this review here.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why I chose this book: &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I actually know a few of the authors on this book, so when they told me about it I wanted to check it out. The premise of the book is exactly as it states in the title - to learn how to solve a problem using products from Microsoft.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What I learned:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I liked the book - a lot. They've arranged the content in a "Solution Decision Framework", that presents a few elements to help you identify a need and then propose alternate solutions to solve them, and then the rationale for the choice. But the payoff is that the authors then walk through the solution they implement and what they ran into doing it.&lt;/p&gt;
&lt;p&gt;I really liked this approach. It's not a huge book, but one I've referred to again since I've read it. It's fairly comprehensive, and includes server-oriented products, not things like Microsoft Office or other client-side tools. In fact, I would LOVE to have a work like this for Open Source and other vendors as well - would make for a&amp;nbsp;great library for a Systems Architect. This one is unashamedly aimed at the Microsoft products, and even if I didn't work here, I'd be fine with that. As I said, it would be interesting to see some books on other platforms like this, but I haven't run across something that presents other systems in quite this way.&lt;/p&gt;
&lt;p&gt;And that brings up an interesting point - This book is aimed at folks who create solutions within an organization. It's not aimed at Administrators, DBA's, Developers or the like, although I think all of those audiences could benefit from reading it. The solutions are made up, and not to a huge level of depth - nor should they be. It's a great exercise in thinking these kinds of things through in a structured way.&lt;/p&gt;
&lt;p&gt;The information is a bit dated, especially for Windows and SQL Azure. While the general concepts hold, the cloud platform from Microsoft is evolving so quickly that any printed book finds it hard to keep up with the improvements.&lt;/p&gt;
&lt;p&gt;I do have one quibble with the text - the chapters are a bit uneven. This is always a danger with multiple authors, but it shows up in a couple of chapters. I winced at one of the chapters that tried to take a more conversational, humorous style. This kind of academic work doesn't lend itself to that style.&lt;/p&gt;
&lt;p&gt;I recommend you get the book - and use it. I hope they keep it updated - I'll be a frequent customer. :)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43364" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Application+Architecture/default.aspx">Application Architecture</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Azure/default.aspx">Azure</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Best+Practices/default.aspx">Best Practices</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Book+Review/default.aspx">Book Review</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Career/default.aspx">Career</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Cloud/default.aspx">Cloud</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Cloud+Computing/default.aspx">Cloud Computing</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Concepts/default.aspx">Concepts</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Design/default.aspx">Design</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Tips/default.aspx">Tips</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Windows+Azure/default.aspx">Windows Azure</category></item><item><title>Messages do not always appear in [catalog].[event_messages] in the order that they occur [SSIS]</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2012/05/15/messages-do-not-always-appear-in-catalog-event-messages-in-the-order-that-they-occur.aspx</link><pubDate>Tue, 15 May 2012 15:07:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43361</guid><dc:creator>jamiet</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;This is a simple heads up for anyone doing SQL Server Integration Services (SSIS) development using SSIS 2012. Be aware that messages do not always appear in &lt;font face="Courier New"&gt;[catalog].[event_messages]&lt;/font&gt; in the order that they occur, observe…&lt;/p&gt;  &lt;p&gt;In the following query I am looking at a subset of messages in &lt;font face="Courier New"&gt;[catalog].[event_messages]&lt;/font&gt; and ordering them by [event_message_id]:&lt;/p&gt;  &lt;pre style="font-size:12px;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;[event_message_id]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;[event_name]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;[message_time]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;[message_source_name]&lt;br /&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;#160;&amp;#160; &lt;/font&gt;&lt;font color="black"&gt;[catalog].[event_messages] em&lt;br /&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHERE&amp;#160; &lt;/font&gt;&lt;font color="black"&gt;[event_message_id] &lt;/font&gt;&lt;font color="gray"&gt;BETWEEN &lt;/font&gt;&lt;font color="black"&gt;290972 &lt;/font&gt;&lt;font color="gray"&gt;AND &lt;/font&gt;&lt;font color="black"&gt;290982&lt;br /&gt;&lt;/font&gt;&lt;font color="blue"&gt;ORDER&amp;#160; BY &lt;/font&gt;&lt;font color="black"&gt;[event_message_id] &lt;/font&gt;&lt;font color="blue"&gt;ASC&lt;br /&gt;&lt;/font&gt;&lt;font color="green"&gt;--ORDER	BY [message_time] ASC&lt;br /&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_09039236.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_7DAA582B.png" width="765" height="301" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take a look at the two rows that I have highlighted, note how the OnPostExecute event for “Utility GetTargetLoadDatesPerETLIfcName” appears after the OnPreExecute event for “FELC Loop over TargetLoadDates”, I happen to know that this is incorrect because “Utility GetTargetLoadDatesPerETLIfcName” is a package that gets executed by an Execute Package Task &lt;i&gt;prior&lt;/i&gt; to the For Each Loop “FELC Loop over TargetLoadDates”:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_22C7A298.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_61B92333.png" width="602" height="158" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we order instead by [message_time] then we see something that makes more sense:&lt;/p&gt;

&lt;pre style="font-size:12px;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;[event_message_id]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;[event_name]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;[message_time]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;[message_source_name]&lt;br /&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;#160;&amp;#160; &lt;/font&gt;&lt;font color="black"&gt;[catalog].[event_messages] em&lt;br /&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHERE&amp;#160; &lt;/font&gt;&lt;font color="black"&gt;[event_message_id] &lt;/font&gt;&lt;font color="gray"&gt;BETWEEN &lt;/font&gt;&lt;font color="black"&gt;290972 &lt;/font&gt;&lt;font color="gray"&gt;AND &lt;/font&gt;&lt;font color="black"&gt;290982&lt;br /&gt;&lt;/font&gt;&lt;font color="green"&gt;--ORDER	BY [event_message_id] ASC&lt;br /&gt;&lt;/font&gt;&lt;font color="blue"&gt;ORDER&amp;#160; BY &lt;/font&gt;&lt;font color="black"&gt;[message_time] &lt;/font&gt;&lt;font color="blue"&gt;ASC&lt;br /&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_6E835384.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_6215305B.png" width="765" height="284" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see that the OnPostExecute for “Utility GetTargetLoadDatesPerETLIfcName” did indeed occur before the OnPreExecute event for “FELC Loop over TargetLoadDates”, they just did not get assigned an &lt;font face="Courier New"&gt;[event_message_id]&lt;/font&gt; in chronological order. We can speculate as to why that might be (I suspect the explanation is something to do with the two executables appearing in different packages) but the reason is not the important thing here, just be aware that you should be ordering by &lt;font face="Courier New"&gt;[message_time]&lt;/font&gt; rather than &lt;font face="Courier New"&gt;[event_message_id] &lt;/font&gt;if you want to get 100% accurate insights into your executions.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43361" width="1" height="1"&gt;</description></item><item><title>How SQL Saturday could be better</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2012/05/15/how-sql-saturday-could-be-better.aspx</link><pubDate>Tue, 15 May 2012 12:58:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43352</guid><dc:creator>AaronBertrand</dc:creator><slash:comments>11</slash:comments><description>I've been to a lot of SQL Saturdays. They are great events to attend - from a community standpoint, from a learning standpoint, and from a speaker growth standpoint. Who could ask for more, right? Great sessions, from passionate speakers willing to both teach and learn, fantastic networking opportunities and lunch. All for free, or at a very low cost - some events need to recover costs and charge $10 for lunch. Still a phenomenal bargain IMHO. But we all know that these events aren't perfect... there...(&lt;a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2012/05/15/how-sql-saturday-could-be-better.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43352" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/community/default.aspx">community</category><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/organizing/default.aspx">organizing</category><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/speaking/default.aspx">speaking</category><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/SQL+Saturday/default.aspx">SQL Saturday</category><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/sqlfamily/default.aspx">sqlfamily</category><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/volunteering/default.aspx">volunteering</category></item><item><title>SQL Server 2008 R2 Service Pack 2 CTP is available</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2012/05/14/sql-server-2008-r2-service-pack-2-ctp-is-available.aspx</link><pubDate>Mon, 14 May 2012 18:23:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43345</guid><dc:creator>AaronBertrand</dc:creator><slash:comments>1</slash:comments><description>You can download the Service Pack 2 CTP from the following URL: http://www.microsoft.com/en-us/download/details.aspx?id=29848 The build # is 10.50.3720. This service pack contains all of the fixes from Service Pack 1 &amp;amp; Cumulative Updates 1 through 5, and a couple of other minor fixes (a couple of SSRS bugs and a bug about an ALTER TABLE batch not being cached correctly). It does not include fixes from Service Pack 1 Cumulative Update #6, which I mentioned recently . You should *NOT* install this...(&lt;a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2012/05/14/sql-server-2008-r2-service-pack-2-ctp-is-available.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43345" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/CTP/default.aspx">CTP</category><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/cumulative+updates/default.aspx">cumulative updates</category><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/hotfixes/default.aspx">hotfixes</category><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/patches/default.aspx">patches</category><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/RTM/default.aspx">RTM</category><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/service+pack+2/default.aspx">service pack 2</category><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/SP2/default.aspx">SP2</category><category domain="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/SQL+Server+2008+R2/default.aspx">SQL Server 2008 R2</category></item><item><title>SQL Rally Presentations</title><link>http://sqlblog.com/blogs/allen_white/archive/2012/05/11/sql-rally-presentations.aspx</link><pubDate>Fri, 11 May 2012 13:48:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43322</guid><dc:creator>AllenMWhite</dc:creator><slash:comments>3</slash:comments><description>As I drove to Dallas for this year's SQL Rally conference (yes, I like to drive) I got a call asking if I could step in for another presenter who had to cancel at the last minute. Life happens, and it's best to be flexible, and I said sure, I can do that. Which presentation would you like me to do? (I'd submitted a few presentations, so it wasn't a problem.) So yesterday I presented "Gathering Performance Metrics With PowerShell" at 8:45AM, and my newest presentation, "Manage SQL Server 2012 on Windows...(&lt;a href="http://sqlblog.com/blogs/allen_white/archive/2012/05/11/sql-rally-presentations.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43322" width="1" height="1"&gt;</description><enclosure url="http://sqlblog.com/blogs/allen_white/attachment/43322.ashx" length="464458" type="application/x-zip-compressed" /><category domain="http://sqlblog.com/blogs/allen_white/archive/tags/Database+Administration/default.aspx">Database Administration</category><category domain="http://sqlblog.com/blogs/allen_white/archive/tags/PASS+Summit/default.aspx">PASS Summit</category><category domain="http://sqlblog.com/blogs/allen_white/archive/tags/PowerShell/default.aspx">PowerShell</category><category domain="http://sqlblog.com/blogs/allen_white/archive/tags/SMO/default.aspx">SMO</category><category domain="http://sqlblog.com/blogs/allen_white/archive/tags/Speaking/default.aspx">Speaking</category></item><item><title>SQLCMD Mode: give it one more chance</title><link>http://sqlblog.com/blogs/maria_zakourdaev/archive/2012/05/11/sqlcmd-mode-give-it-one-more-chance.aspx</link><pubDate>Fri, 11 May 2012 13:26:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43318</guid><dc:creator>Maria Zakourdaev</dc:creator><slash:comments>5</slash:comments><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;- Click on me. Choose me. - asked one forgotten &lt;font color="#000000"&gt;feature when some bored DBA was purposelessly&lt;/font&gt; wondering through the Management Studio menu at the end of her long and busy working day.&lt;/p&gt;  &lt;p&gt;- Why would I use you? I have heard of no one who does. What are you for? - perplexedly wondered aged and wise DBA. At least that DBA thought she was aged and wise though each day tried to prove to her that she wasn't. &lt;/p&gt;  &lt;p&gt;- I know you. You are quite lazy. Why would you do additional clicks to move from window to window? From Tool to tool ? This is irritating, isn't it? I can run windows system commands, sql statements and much more from the same script, from the same query window!&lt;/p&gt;  &lt;p&gt;- I have all my tools that I‘m used to, I have Management Studio, Cmd, Powershell. They can do anything for me. I don’t need additional tools.&lt;/p&gt;  &lt;p&gt;- I promise you, you will like me. – the thing continued to whine .&lt;/p&gt;  &lt;p&gt;- All right, show me. – she gave up. It’s always this way, she thought sadly, - easier to agree than to explain why you don’t want.&lt;/p&gt;  &lt;p&gt;- Enable me and then think about anything that you always couldn’t do through the management studio and had to use other tools. &lt;/p&gt;  &lt;p&gt;- Ok. Google for me the list of greatest features of SQL SERVER 2012.&lt;/p&gt;  &lt;p&gt;- Well... I’m not sure... Think about something else. &lt;/p&gt;  &lt;p&gt;- Ok, here is something easy for you. I want to check if file folder exists or if file is there. Though, I can easily do this using xp_cmdshell …&lt;/p&gt;  &lt;p&gt;- This is easy for me. – rejoiced the feature. &lt;/p&gt;  &lt;p&gt;By the way, having the items of the menu talking to you usually means you should stop working and go home. Or drink coffee. Or both. Well, aged and wise dba wasn’t thinking about the weirdness of the situation at that moment.&lt;/p&gt;  &lt;p&gt;- After enabling me, – said unfairly forgotten feature (it was thinking of itself in such manner) – after enabling me you can use all command line commands in the same management studio query window by adding two exclamation marks &lt;font style="background-color:#00ff00;"&gt;!!&lt;/font&gt; at the beginning of the script line to denote that you want to use cmd command:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/maria_zakourdaev/image_5FBC6A4C.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" width="477" height="327" src="http://sqlblog.com/blogs/maria_zakourdaev/image_thumb_0BC94171.png"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;-Just keep in mind that when using this feature, you are actually running the commands ON YOUR computer and not on SQL server that query window is connected to. This is main difference from using xp_cmdshell which is executing commands on sql server itself. Bottomline, use UNC path instead of local path. &lt;/p&gt;  &lt;p&gt;- Look, there are much more than that. - The SQLCMD feature was getting exited.- You can get IP of your servers, create, rename and drop folders. You can see the contents of any file anywhere and even start different tools from the same query window:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/maria_zakourdaev/image_3D7438F9.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" width="463" height="463" src="http://sqlblog.com/blogs/maria_zakourdaev/image_thumb_4D33CDFD.png"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Not so aged and wise DBA was getting interested: - I also want to run different scripts on different servers without changing connection of the query window. &lt;/p&gt;  &lt;p&gt;- Sure, sure! Another great feature that CMDmode is providing us with and giving more power to querying. Use &lt;font style="background-color:#00ff00;"&gt;“:”&lt;/font&gt; to use additional features, like &lt;font style="background-color:#00ff00;"&gt;:connect&lt;/font&gt; that allows you to change connection: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/maria_zakourdaev/image_3861D57D.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" width="460" height="369" src="http://sqlblog.com/blogs/maria_zakourdaev/image_thumb_3ABB577B.png"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;- Now imagine, you have one script where you have all your changes, like creating staging table on the DWH staging server, adding fact table to DWH itself and updating stored procedures in the server where reporting database is located.&lt;/p&gt;  &lt;p&gt;- Now, give me more challenges!&lt;/p&gt;  &lt;p&gt;- Script out a list of stored procedures into the text files. &lt;/p&gt;  &lt;p&gt;- You can do it easily by using command&lt;font style="background-color:#00ff00;"&gt; :out&lt;/font&gt; which will write the query results into the specified text file. The output can be the code of the stored procedure or any data. Actually this is the same as changing the query output into the file instead of the grid.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/maria_zakourdaev/image_18171900.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" width="452" height="411" src="http://sqlblog.com/blogs/maria_zakourdaev/image_thumb_15FA1A37.png"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;- Now, take all of the scripts and run all of them, one by one, on the different server.&amp;nbsp; &lt;/p&gt;  &lt;p&gt;- Easily &lt;/p&gt;  &lt;p&gt;- Come on... I’m sure that you can not...&lt;/p&gt;  &lt;p&gt;-Why not? Naturally, I can do it using &lt;font style="background-color:#00ff00;"&gt;:r&lt;/font&gt; commant which is opening a script and executing it. Look, I can also use &lt;font style="background-color:#00ff00;"&gt;:setvar&lt;/font&gt; command to define an environment variable in SQLCMD mode. Just note that you have to leave the empty string between :r commands, otherwise it’s not working although I have no idea why.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/maria_zakourdaev/image_012821B7.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" width="362" height="202" src="http://sqlblog.com/blogs/maria_zakourdaev/image_thumb_1153E9B0.png"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;- Wow.- She was really impressed. - Ok, I’ll go to try all those…&lt;/p&gt;  &lt;p&gt;-Wait, wait! I know how to google the SQL SERVER features for you! This example will open chrome explorer with search results for the “SQL server 2012 top features” ( change the path to suit your PC): &lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/maria_zakourdaev/image_11DFA698.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" width="1027" height="149" src="http://sqlblog.com/blogs/maria_zakourdaev/image_thumb_6FA79B11.png"&gt;&lt;/a&gt;&lt;/p&gt;                            &lt;p&gt;“Well, this can be probably useful stuff, maybe this feature is really unfairly forgotten”, thought the DBA while going through the dark empty parking lot to her lonely car. “As someone really wise once said: “It is what we think we know that keeps us from learning. Learn, unlearn and relearn”.&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43318" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/maria_zakourdaev/archive/tags/sqlcmd/default.aspx">sqlcmd</category></item><item><title>DATEFROMPARTS</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2012/05/10/datefromparts.aspx</link><pubDate>Thu, 10 May 2012 08:53:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43310</guid><dc:creator>jamiet</dc:creator><slash:comments>4</slash:comments><description>&lt;p&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;I recently overheard a remark by&amp;nbsp;&lt;a href="http://sqlblog.com/blogs/greg_low/" target="_blank"&gt;Greg Low&lt;/a&gt;&amp;nbsp;in which he said something akin to "the most interesting parts of a new SQL Server release are the myriad of small things that are in there that make a developer's life easier" (I'm paraphrasing because I can't remember the actual quote but it was something like that).&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;The new &lt;a href="http://msdn.microsoft.com/en-us/library/hh213228.aspx" target="_blank"&gt;DATEFROMPARTS&lt;/a&gt; function is a classic example of that . It simply takes three&amp;nbsp;integer parameters and builds a date out of them (if you have used &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2009/12/10/fun-and-games-with-reporting-services-expressions.aspx" target="_blank"&gt;DateSerial&lt;/a&gt; in Reporting Services then you'll understand).&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;Take the following code which&amp;nbsp;generates the first and last day of some given years:&lt;/span&gt;&lt;/p&gt;

&lt;pre style="font-size:12px;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;2008 &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;Yr &lt;/font&gt;&lt;font color="blue"&gt;INTO &lt;/font&gt;&lt;font color="#434343"&gt;#Years &lt;/font&gt;&lt;font color="blue"&gt;UNION &lt;/font&gt;&lt;font color="gray"&gt;ALL &lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;2009 &lt;/font&gt;&lt;font color="blue"&gt;UNION &lt;/font&gt;&lt;font color="gray"&gt;ALL &lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;2010 &lt;/font&gt;&lt;font color="blue"&gt;UNION &lt;/font&gt;&lt;font color="gray"&gt;ALL &lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;2011 &lt;/font&gt;&lt;font color="blue"&gt;UNION &lt;/font&gt;&lt;font color="gray"&gt;ALL &lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;2012&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;[FirstDayOfYear] &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;DATE&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;CHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;8&lt;/font&gt;&lt;font color="gray"&gt;),((&lt;/font&gt;&lt;font color="black"&gt;y.[Yr] &lt;/font&gt;&lt;font color="gray"&gt;* &lt;/font&gt;&lt;font color="black"&gt;10000&lt;/font&gt;&lt;font color="gray"&gt;) + &lt;/font&gt;&lt;font color="black"&gt;101&lt;/font&gt;&lt;font color="gray"&gt;)))&lt;br&gt;,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[LastDayOfYear]  &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;DATE&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;CHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;8&lt;/font&gt;&lt;font color="gray"&gt;),((&lt;/font&gt;&lt;font color="black"&gt;y.[Yr] &lt;/font&gt;&lt;font color="gray"&gt;* &lt;/font&gt;&lt;font color="black"&gt;10000&lt;/font&gt;&lt;font color="gray"&gt;) + &lt;/font&gt;&lt;font color="black"&gt;1231&lt;/font&gt;&lt;font color="gray"&gt;)))&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;#Years &lt;/font&gt;&lt;font color="black"&gt;y&lt;br&gt;&lt;/font&gt;&lt;/pre&gt;&lt;font color="black"&gt;&lt;/font&gt;

&lt;pre style="font-size:12px;"&gt;here are the results:&lt;/pre&gt;

&lt;p&gt;&lt;img src="http://jamiekt.files.wordpress.com/2012/05/firstlast.png"&gt;
&lt;/p&gt;

&lt;p&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;That code is pretty gnarly though with those CONVERTs in there&amp;nbsp;and, worse, if the character string is constructed in a certain way then it could fail due to localisation, check this out:&lt;/span&gt;&lt;/p&gt;

&lt;pre style="font-size:12px;"&gt;&lt;font color="blue"&gt;SET &lt;/font&gt;&lt;font color="black"&gt;LANGUAGE french&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;dt&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;Month_Name&lt;/font&gt;&lt;font color="blue"&gt;=&lt;/font&gt;&lt;font color="magenta"&gt;DATENAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;mm&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;dt&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dt &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;DATETIME&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;CHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;4&lt;/font&gt;&lt;font color="gray"&gt;),&lt;/font&gt;&lt;font color="black"&gt;y.[Yr]&lt;/font&gt;&lt;font color="gray"&gt;) + &lt;/font&gt;&lt;font color="red"&gt;N'-01-02'&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;#Years &lt;/font&gt;&lt;font color="black"&gt;y&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;)&lt;/font&gt;&lt;font color="black"&gt;d&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SET &lt;/font&gt;&lt;font color="black"&gt;LANGUAGE us_english&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;dt&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;Month_Name&lt;/font&gt;&lt;font color="blue"&gt;=&lt;/font&gt;&lt;font color="magenta"&gt;DATENAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;mm&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;dt&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dt &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;DATETIME&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;CHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;4&lt;/font&gt;&lt;font color="gray"&gt;),&lt;/font&gt;&lt;font color="black"&gt;y.[Yr]&lt;/font&gt;&lt;font color="gray"&gt;) + &lt;/font&gt;&lt;font color="red"&gt;N'-01-02'&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;#Years &lt;/font&gt;&lt;font color="black"&gt;y&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;)&lt;/font&gt;&lt;font color="black"&gt;d&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;
&lt;img src="http://jamiekt.files.wordpress.com/2012/05/datetime_localisation1.png"&gt;
&lt;p&gt;Notice how the datetime has been&amp;nbsp;converted differently based on the language setting. When French, the string "2012-01-02" gets interpreted as 1st February whereas when us_english the same string is interpreted as 2nd January.&lt;/p&gt;

&lt;p&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;Instead of all this CONVERTing nastiness&amp;nbsp;we have &lt;font color="magenta"&gt;DATEFROMPARTS&lt;/font&gt;:&lt;/span&gt;&lt;/p&gt;

&lt;pre style="font-size:12px;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;[FirstDayOfYear] &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="magenta"&gt;DATEFROMPARTS&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;y.[Yr]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;,&amp;nbsp;&amp;nbsp;&amp;nbsp;   &lt;/font&gt;&lt;font color="black"&gt;[LasttDayOfYear] &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="magenta"&gt;DATEFROMPARTS&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;y.[Yr]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;12&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;31&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;#Years &lt;/font&gt;&lt;font color="black"&gt;y&lt;br&gt;&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;How much nicer&amp;nbsp;is that? The bad news of course is that you have to upgrade to SQL Server 2012 or migrate to SQL Azure if you want to use it, as is the way of the world!&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;Don't forget that if you want to try this code out on SQL Azure right this second, for free, you can do so by connecting up to &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2012/03/27/adventureworks2012-now-available-to-all-on-sql-azure.aspx" target="_blank"&gt;AdventureWorks On Azure&lt;/a&gt;. You don't even need to have SSMS handy - a browser that runs Silverlight will do just fine. Simply head to &lt;a href="https://mhknbn2kdz.database.windows.net/" target="_blank"&gt;https://mhknbn2kdz.database.windows.net/&lt;/a&gt;&amp;nbsp;and use the following credentials:&lt;/span&gt;&lt;/p&gt;
&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;
&lt;li&gt;&lt;b&gt;Database&lt;/b&gt; AdventureWorks2012&lt;/li&gt;

&lt;li&gt;&lt;b&gt;User&lt;/b&gt; sqlfamily&lt;/li&gt;

&lt;li&gt;&lt;b&gt;Password&lt;/b&gt; sqlf@m1ly&lt;br&gt;&lt;/li&gt;
&lt;/span&gt;
&lt;p&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;One caveat, SELECT INTO doesn't work on SQL Azure so you'll have to use this instead:&lt;/span&gt;&lt;/p&gt;

&lt;pre style="font-size:12px;"&gt;&lt;font color="blue"&gt;DECLARE &lt;/font&gt;&lt;font color="#434343"&gt;@y &lt;/font&gt;&lt;font color="blue"&gt;TABLE &lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt; &lt;/font&gt;&lt;font color="black"&gt;[Yr] &lt;/font&gt;&lt;font color="blue"&gt;INT&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;INSERT &lt;/font&gt;&lt;font color="#434343"&gt;@y&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;[Yr]&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;2008 &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;Yr &lt;/font&gt;&lt;font color="blue"&gt;UNION &lt;/font&gt;&lt;font color="gray"&gt;ALL &lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;2009 &lt;/font&gt;&lt;font color="blue"&gt;UNION &lt;/font&gt;&lt;font color="gray"&gt;ALL &lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;2010 &lt;/font&gt;&lt;font color="blue"&gt;UNION &lt;/font&gt;&lt;font color="gray"&gt;ALL &lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;2011 &lt;/font&gt;&lt;font color="blue"&gt;UNION &lt;/font&gt;&lt;font color="gray"&gt;ALL &lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;2012&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;[FirstDayOfYear] &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="magenta"&gt;DATEFROMPARTS&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;y.[Yr]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[LastDayOfYear]  &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="magenta"&gt;DATEFROMPARTS&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;y.[Yr]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;12&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;31&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="#434343"&gt;@y &lt;/font&gt;&lt;font color="black"&gt;y&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;[FirstDayOfYear] &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;DATE&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;CHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;8&lt;/font&gt;&lt;font color="gray"&gt;),((&lt;/font&gt;&lt;font color="black"&gt;y.[Yr] &lt;/font&gt;&lt;font color="gray"&gt;* &lt;/font&gt;&lt;font color="black"&gt;10000&lt;/font&gt;&lt;font color="gray"&gt;) + &lt;/font&gt;&lt;font color="black"&gt;101&lt;/font&gt;&lt;font color="gray"&gt;)))&lt;br&gt;,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[LastDayOfYear]  &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;DATE&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;CHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;8&lt;/font&gt;&lt;font color="gray"&gt;),((&lt;/font&gt;&lt;font color="black"&gt;y.[Yr] &lt;/font&gt;&lt;font color="gray"&gt;* &lt;/font&gt;&lt;font color="black"&gt;10000&lt;/font&gt;&lt;font color="gray"&gt;) + &lt;/font&gt;&lt;font color="black"&gt;1231&lt;/font&gt;&lt;font color="gray"&gt;)))&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="#434343"&gt;@y &lt;/font&gt;&lt;font color="black"&gt;y&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;&lt;a href="http://twitter.com/jamiet" target="_blank"&gt;@Jamiet&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43310" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SQL+Server+2012/default.aspx">SQL Server 2012</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/t-sql/default.aspx">t-sql</category></item><item><title>Speaking at SQLRelay. Will you be there?</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2012/05/09/speaking-at-sqlrelay-will-you-be-there.aspx</link><pubDate>Wed, 09 May 2012 12:26:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43292</guid><dc:creator>jamiet</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;SQL Relay (&lt;a href="https://twitter.com/#!/search/sqlrelay" target="_blank"&gt;#sqlrelay&lt;/a&gt;)&amp;nbsp;is fast approaching and I wanted to take this opportunity to tell you a little about it.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;SQL Relay is a&amp;nbsp;5-day tour around the UK that is taking in five Server Server user groups, each one comprising a full day of SQL Server related learnings. The dates and venues are:&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://sqlserverfaq.com/default.aspx?item=event&amp;amp;itemid=378" target="_blank"&gt;21st May, Edinburgh&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://sqlserverfaq.com/default.aspx?item=event&amp;amp;itemid=373" target="_blank"&gt;22nd May, Manchester&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://sqlserverfaq.com/default.aspx?item=event&amp;amp;itemid=357" target="_blank"&gt;23rd May, Birmingham&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://sqlserverfaq.com/default.aspx?item=event&amp;amp;itemid=391" target="_blank"&gt;24th May, Bristol&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://sqlserverfaq.com/default.aspx?item=event&amp;amp;itemid=377" target="_blank"&gt;30th May, London&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Click on the appropriate link to see the full agenda and to book your spot.&lt;/p&gt;&lt;p&gt;SQL Relay features some of this country's most prominent SQL Server speakers including &lt;a href="http://twitter.com/#!/technitrain" target="_blank"&gt;Chris Webb&lt;/a&gt;, &lt;a href="http://twitter.com/#!/tonyrogerson" target="_blank"&gt;Tony Rogerson&lt;/a&gt;, &lt;a href="http://twitter.com/#!/deepfat" target="_blank"&gt;Andrew Fryer&lt;/a&gt;, Martin Bell, &lt;a href="http://twitter.com/#!/allanSQLIS" target="_blank"&gt;Allan Mitchell&lt;/a&gt;, Steve Shaw, Gordon Meyer, Satya Jayanty, &lt;a href="https://twitter.com/#!/ctesta_oneill" target="_blank"&gt;Chris Testa O'Neill&lt;/a&gt;, &lt;a href="https://twitter.com/#!/duncansutcliffe" target="_blank"&gt;Duncan Sutcliffe&lt;/a&gt;, Rob Carrol, &lt;a href="https://twitter.com/#!/jamiet" target="_blank"&gt;me&lt;/a&gt;&amp;nbsp;and SQL Server UK Product Manager Morris Novello so I really encourage you to go - you have my word it'll be an informative and, more importantly, enjoyable day out from your regular 9-to-5.&lt;/p&gt;&lt;p&gt;I am presenting my session "A Lap Around the SSIS Catalog" at Edinburgh and Manchester so if you're going, I hope to see you there.&lt;/p&gt;&lt;p&gt;&lt;a href="https://twitter.com/#!/jamiet" target="_blank"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43292" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SQl+Relay/default.aspx">SQl Relay</category></item><item><title>Publish Profile Files in SQL Server Data Tools (SSDT)</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2012/05/09/publish-profile-files-in-sql-server-data-tools-ssdt.aspx</link><pubDate>Tue, 08 May 2012 22:07:36 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43267</guid><dc:creator>jamiet</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;I have been using &lt;a href="http://msdn.microsoft.com/en-us/data/gg427686" target="_blank"&gt;SQL Server Data Tools&lt;/a&gt; (SSDT) both at work and on some hobby projects for quite a few weeks now and of all the new features I have to say the one that I am appreciating the most is Publish Profile files. I have been searching around on MSDN for an article that explains Publish Profile files but it seems no such article exists so I’ll attempt to surmise here.&lt;/p&gt;  &lt;p&gt;Publish Profile files are, essentially, a collection of all the property key-value pairs that are needed to deploy a database model (i.e. a &lt;a href="http://www.fileinfo.com/extension/dacpac" target="_blank"&gt;.dacpac&lt;/a&gt;) to some target database. Those properties include (but are not limited to):&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;database name&lt;/li&gt;    &lt;li&gt;connection string&lt;/li&gt;    &lt;li&gt;whether or not to publish SSDT projects on which the current project has a dependency&lt;/li&gt;    &lt;li&gt;Recreate the database from scratch (or not)&lt;/li&gt;    &lt;li&gt;Backup before deploy&lt;/li&gt;    &lt;li&gt;Drop unknown objects in target&lt;/li&gt;    &lt;li&gt;SQLCMD Variables&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Those that have used the predecessor to SSDT, Visual Studio Database Projects, will be familiar with a lot of those properties however in that case the properties had to be specified on a case-by-case basis; typically in an msbuild script or similar. Often those scripts are not maintained by a developer – rather they are maintained by a &lt;a href="http://en.wikipedia.org/wiki/DevOps" target="_blank"&gt;DevOps&lt;/a&gt; team that are not familiar with the code being deployed and as a developer myself that’s not a situation that I’m at all comfortable with. On my most recent project where Visual Studio Database Projects were being used I faced the maddening situation where every new SQLCMD variable added to a project required an email to be sent to the DevOps team to ask them to update their scripts accordingly. As you can imagine human errors crept in (on our side more than the DevOps side) and we ended up deploying projects with the wrong SQLCMD values. Moreover, we had to deal with different DevOps folks and often they would store the values in different places; totally infuriating, believe me.&lt;/p&gt;  &lt;p&gt;Publish Profile files make this process much easier because we can define all those properties on a per-environment basis and keep them in a dedicated Publish Profile file. The obvious benefit then is that a Publish Profile file &lt;em&gt;abstracts&lt;/em&gt; all of the environment-specific information into a single file so deploying an SSDT project now requires only two things; the build output (i.e. a .dacpac file) and a Publish Profile file:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font face="Courier New"&gt;&amp;gt;sqlpackage.exe /sf:MyDB.dacpac /pr:DEV.publish.xml&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The implied benefit (and this is what I really like about them) is that Publish Profile files are a source code artefact that a developer maintains the same as they would any other source code artefact, all that the DevOps people need are the build output (i.e. a .dacpac file) and an appropriately named Publish Profile file. Developers are now wholly in charge of how their code gets deployed which keeps them happy and the DevOps people have less work to do – so they’re a happy bunch too! I’m not saying that the wrong values won’t ever be supplied but at least now we know exactly where to go to fix those errors.&lt;/p&gt;  &lt;p&gt;SSDT also provides a friendly UI for maintaining these Publish Profile files. Double-click on one and this UI appears:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_4D2EC0B8.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_5F97116D.png" width="517" height="510" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Its fairly self-explanatory to fill these things out. A connection string, a database name and values for each SQLCMD variable defined within the project and you’re pretty much there. (I have written previously about one other benefit of Publish Profile files - that they can be used to make SQLCMD variables mandatory. Read more at &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2012/02/12/sql-server-data-tools-does-support-required-variables.aspx" target="_blank"&gt;SQL Server Data Tools does support required variables&lt;/a&gt;.)&lt;/p&gt;  &lt;p&gt;One minor downside of Publish Profile files is that they get created in the root of your SSDT project (I have griped about this previously at &lt;a href="http://sqlblog.com/blogs/jamie_thomson/archive/2012/04/15/folders-in-sql-server-data-tools.aspx" target="_blank"&gt;Folders in SQL Server Data Tools&lt;/a&gt;) so the convention that I have been using is to create a folder called Publish in each SSDT project and move all Publish Profile files into there.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_5DE64599.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_5D0DDFAF.png" width="300" height="185" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Hopefully this has given you a small taster of what Publish Profile files are all about. I’ll probably share some msbuild scripts that we’re using to deploy these things in a later blog post.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;P.S. As an aside, I have requested that the SSIS/SSAS/SSRS teams adopt the Publish Profile file approach in future iterations of their products. If you think that that is something you would like to see happen then &lt;a href="https://connect.microsoft.com/sqlserver/feedback/details/740059/ssis-collect-all-deployment-specific-properties-into-a-single-file#details" target="_blank"&gt;click through, vote and leave a comment&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43267" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/Deployment/default.aspx">Deployment</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/sql+server/default.aspx">sql server</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SQL+Server+2012/default.aspx">SQL Server 2012</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SQL+Server+Data+Tools/default.aspx">SQL Server Data Tools</category><category domain="http://sqlblog.com/blogs/jamie_thomson/archive/tags/SSDT/default.aspx">SSDT</category></item><item><title>The ethical question</title><link>http://sqlblog.com/blogs/rob_farley/archive/2012/05/09/the-ethical-question.aspx</link><pubDate>Tue, 08 May 2012 19:56:33 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43266</guid><dc:creator>Rob Farley</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;Some people question the ethics of writing about my company on my blog. But I don’t have a problem with it. Is it ethical to ignore the concerns of others and to just do what I want?&lt;a href="http://chrisshaw.wordpress.com/2012/04/30/a-dbas-ethics-t-sql-tuesday-30/" target="_blank"&gt;&lt;img style="background-image:none;border-right-width:0px;margin:5px;padding-left:0px;padding-right:0px;display:inline;float:right;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="TSQL2sDay150x150" border="0" alt="TSQL2sDay150x150" align="right" src="http://sqlblog.com/blogs/rob_farley/TSQL2sDay150x150_05377C71.jpg" width="170" height="170" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Anyway – it’s relevant for this month’s T-SQL Tuesday, which &lt;a href="http://chrisshaw.wordpress.com/2012/04/30/a-dbas-ethics-t-sql-tuesday-30/" target="_blank"&gt;Chris Shaw is hosting on the topic of ethics&lt;/a&gt;, so I’m going to write a few things about integrity and ethics.&lt;/p&gt;  &lt;p&gt;When I hire people to work at LobsterPot Solutions, the main thing I look for is a high level of integrity. I can handle a certain level of technical unfamiliarity – that’s something that can be learned. But I can’t teach integrity in the same way. I can foster it, and I can ensure that it’s an established ‘value’ in the company. It’s the number one thing.&lt;/p&gt;  &lt;p&gt;I know a sysadmin company (it wasn’t LobsterPot) that recently lost a bunch of client data – they asked us to help them recover some of the lost data. It was a bad technical mistake they made, but that’s forgivable. They tried really hard to get the data back, and managed to salvage a lot of it, which demonstrated a better level of integrity. When I look at ethics and integrity, it’s not about mistakes, it’s more about the response to mistakes. Their integrity was brought into question over putting the client into a situation where they could’ve lost data – but this wasn’t a question of integrity, it was an honest mistake. The integrity question comes about their response. I like to look at the knee-jerk reaction. If you make a mistake, do you cover it up, or do you try to resolve it? Unfortunately, I think there’s often an element of both, but if the motivation is to protect the other people involved, then I would expect that the integrity level is okay.&lt;/p&gt;  &lt;p&gt;   &lt;p&gt;Ethics is about good and bad behaviour, and of course, once that definition has been made, choosing good. I’m not going to try to do the definition thing – I think people generally have a feel for what is good and bad (even with data it should be clear – you don’t get to steal client data, etc). The application of ethics comes down to integrity.&lt;/p&gt;    &lt;p&gt;At LobsterPot, we try to do the right thing all the time. This doesn’t mean that we don’t make mistakes – but our first reaction is always to &lt;strong&gt;do the right thing by the other parties involved&lt;/strong&gt;, even if it costs us money.&lt;/p&gt;    &lt;p&gt;It has to. We don’t get a choice on this. And if I don’t think that integrity is your driving influence for every decision you make, then I’m sorry, but I’m just not going to hire you.&lt;/p&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43266" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/rob_farley/archive/tags/t-sql+tuesday/default.aspx">t-sql tuesday</category></item><item><title>BlobShare: Corporate Filesharing with Security and Control</title><link>http://sqlblog.com/blogs/buck_woody/archive/2012/05/08/blobshare-corporate-filesharing-with-security-and-control.aspx</link><pubDate>Tue, 08 May 2012 12:49:21 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43261</guid><dc:creator>BuckWoody</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;We’ve all done it. We have a file we need to transfer to someone&amp;#160; - but it’s big. Really big. “Big”, in this case, is defined as “bigger than my corporate e-mail will let me send.” So of course we scout around, and find a free file share location. We plop it in, and send a link to the other person. Problem solved!&lt;/p&gt;  &lt;p&gt;No, problem created. You see, many of these file-sharing sites have some…interesting…language in their terms. Sure, for a picture of aunt Sally riding that llama on the vacation, who cares if someone else steals it and puts it on an advertisement for a &lt;a href="http://en.wikipedia.org/wiki/Elbonia#Elbonia" target="_blank"&gt;shipping company from Elbonia&lt;/a&gt;? But most of these offerings were not designed for a corporation with private or secure information - sometimes your private or secure information. &lt;/p&gt;  &lt;p&gt;So what’s a company to do? You have to let people send files - they are just going to work around IT if you don’t - but you need a way to keep it secure, and maintain a chain of custody in some cases. There is a solution.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blobshare.codeplex.com/" target="_blank"&gt;There’s a free Codeplex project called “BlobShare” that we have for you here&lt;/a&gt;. You pull it down, follow the instructions, and deploy it to Windows and SQL Azure. From there, you have a clean, safe, secure, controlled interface to let your folks share files. &lt;/p&gt;  &lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-26-94-metablogapi/7870.image_5F00_3558ACBA.png" /&gt;&lt;/p&gt;  &lt;p&gt;There’s a full post on the inner-workings and the design of this code - and it’s just code. You can change it, use your own logo, restrict it further, loosen it up, whatever you like. That’s the point of Platform as a Service - control and ease. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/b/vbertocci/archive/2011/10/31/blobshare-sample-acs-protected-file-sharing.aspx"&gt;http://blogs.msdn.com/b/vbertocci/archive/2011/10/31/blobshare-sample-acs-protected-file-sharing.aspx&lt;/a&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43261" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Azure/default.aspx">Azure</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Azure+Use+Cases/default.aspx">Azure Use Cases</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Web/default.aspx">Web</category><category domain="http://sqlblog.com/blogs/buck_woody/archive/tags/Windows+Azure/default.aspx">Windows Azure</category></item><item><title>SQLIO analysis on Excel charts</title><link>http://sqlblog.com/blogs/marco_russo/archive/2012/05/08/sqlio-analysis-on-excel-charts.aspx</link><pubDate>Tue, 08 May 2012 10:20:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43237</guid><dc:creator>Marco Russo (SQLBI)</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I tend to use twitter when I have to notify an interesting link or tool. But sometimes a blog post (even if short) is better, because allows me to easily find it on search engines (Bing/Google/whatever) months or years later. I know PInterest is growing these days, but the blog indexed on search engines is still a reliable resource to me.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.davidemauri.it/"&gt;Davide Mauri&lt;/a&gt; tweeted this &lt;a href="http://www.sqlskills.com/BLOGS/PAUL/post/Cool-free-tool-to-parse-and-analyze-SQLIO-results.aspx"&gt;Pual Randal’s blog&lt;/a&gt; that mention the &lt;a href="http://tools.davidklee.net/sqlio.aspx"&gt;SQLIO Result Parser&lt;/a&gt; tool from David Klee. In short: you run SQLIO, save result in a CSV file, upload these results on a web page and obtain an Excel file as a result, including charts. Simple and useful. I’ll use it!&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43237" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/marco_russo/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>Did You Know? Turning Off Locking</title><link>http://sqlblog.com/blogs/kalen_delaney/archive/2012/05/07/turning-off-locking.aspx</link><pubDate>Mon, 07 May 2012 23:35:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43250</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>10</slash:comments><description>Back when the lock manager was rewritten for SQL Server 7, and row level locking was added to the product, the procedure sp_indexoption gave us the ability to turn OFF either row or page locks or both, for one particular index, or for a table and all the indexes on it. I must admit, I rarely found this option to be the solution to any sticky problems, although while doing some quick research prior to writing this post, I did find that Microsoft recommended turning off locking options on a couple...(&lt;a href="http://sqlblog.com/blogs/kalen_delaney/archive/2012/05/07/turning-off-locking.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43250" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/kalen_delaney/archive/tags/locking/default.aspx">locking</category><category domain="http://sqlblog.com/blogs/kalen_delaney/archive/tags/metadata/default.aspx">metadata</category></item><item><title>PHP Setup for IIS and SQL Server</title><link>http://sqlblog.com/blogs/davide_mauri/archive/2012/05/07/php-setup-for-iis-and-sql-server.aspx</link><pubDate>Mon, 07 May 2012 15:20:50 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43244</guid><dc:creator>Davide Mauri</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;Making PHP running on IIS and configuring it to be able to connect and query a SQL Server database is quite easy. If just need to get pointed to the correct direction, since information are spread all across the web but sometimes is not easy to understand to which version they apply.&lt;/p&gt;  &lt;p&gt;So, since our primary goal is to have &lt;strong&gt;Wordpress 3.3.2&lt;/strong&gt; (the latest version as of 07 May 2012) and &lt;strong&gt;PHPBB 3.0.12&lt;/strong&gt; (the latest version as of 07 May 2012) up and running, we’ll download the latest &lt;strong&gt;PHP 5.3&lt;/strong&gt; version (PHP 5.4 has been reported to have some problems with the current version of Wordpress so we won’t go for the latest one).&lt;/p&gt;  &lt;p&gt;So the first step is to&lt;em&gt; download PHP 5.3.12 version from PHP.NET web site&lt;/em&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://windows.php.net/download/" href="http://windows.php.net/download/"&gt;http://windows.php.net/download/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As you may notice there are tow flavor of the PHP distribution: Thread Safe and Non Thread Safe (NTS).&lt;/p&gt;  &lt;p&gt;I’ve googled/binged a bit to understand what’s the advised flavor and as you can read here&lt;/p&gt;  &lt;p&gt;&lt;a title="http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis/" href="http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis/"&gt;http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis/&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;the best practice is to use the NTS flavor.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;I downloaded the Zip package, and unzipped the files in a newly created PHP directory under C: drive (C:\PHP)&lt;/p&gt;  &lt;p&gt;The above link also pointed me to a resource page very helpful for everyone trying to install PHP and configure on IIS:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://learn.iis.net/page.aspx/24/running-php-applications-on-iis/" href="http://learn.iis.net/page.aspx/24/running-php-applications-on-iis/"&gt;http://learn.iis.net/page.aspx/24/running-php-applications-on-iis/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The following link give also additional information&lt;/p&gt;  &lt;p&gt;&lt;a title="http://php.net/manual/en/install.windows.iis7.php" href="http://php.net/manual/en/install.windows.iis7.php"&gt;http://php.net/manual/en/install.windows.iis7.php&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I also found a very nice IIS Add-on that allows you to manage PHP directly from IIS:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://phpmanager.codeplex.com/" href="http://phpmanager.codeplex.com/"&gt;http://phpmanager.codeplex.com/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;One installed the PHP Manager, you can check that everything is working simply checking that PHPINFO() works:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/davide_mauri/image_2BA20BA0.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/davide_mauri/image_thumb_1814ABFF.png" width="244" height="224" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/davide_mauri/image_4FE6F022.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/davide_mauri/image_thumb_6D78CB21.png" width="244" height="199" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;To be able to use SQL Server from PHP you need the PHP SQL Server Drivers provided by Microsoft:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://blogs.iis.net/sqlphp/archive/2012/03/22/microsoft-drivers-3-0-1-for-php-for-sql-server-with-php-5-4-support-released.aspx" href="http://blogs.iis.net/sqlphp/archive/2012/03/22/microsoft-drivers-3-0-1-for-php-for-sql-server-with-php-5-4-support-released.aspx"&gt;http://blogs.iis.net/sqlphp/archive/2012/03/22/microsoft-drivers-3-0-1-for-php-for-sql-server-with-php-5-4-support-released.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a title="http://sqlsrvphp.codeplex.com/" href="http://sqlsrvphp.codeplex.com/"&gt;http://sqlsrvphp.codeplex.com/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Once the file has ben downloaded I extracted it to a C:\PHPSQLSRVfolder.&lt;/p&gt;  &lt;p&gt;Now you must acknowledge PHP that they exists and should be used. You can do it directly modifying your &amp;lt;php install folder&amp;gt;\php.ini file, adding the reference to the extension, &lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/davide_mauri/image_05300288.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/davide_mauri/image_thumb_597F388B.png" width="244" height="67" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;begin sure to have copied the correct .dll file into the &amp;lt;php install folder&amp;gt;\ext folder.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/davide_mauri/image_63D05CEB.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/davide_mauri/image_thumb_576239C2.png" width="244" height="122" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;if you have installed the PHP Manager, you can also enable/disable extension from here (.dll file must be manually copied into the /ext directory anyway)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/davide_mauri/image_484B5AE8.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/davide_mauri/image_thumb_3BDD37BF.png" width="244" height="142" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As you may have noticed, after having unzipped the PHP SQL Server Drivers&amp;#160; you have a bunch of files to choose from. Which is the one right for you? For the configuration we’ve chosen we have to go for the “standard” (which means not the “pdo” driver), non-thread safe PHP 5.3 driver. As you can guess the file we need is &lt;/p&gt;  &lt;p&gt;php_sqlsrv_53_nts.dll&lt;/p&gt;  &lt;p&gt;After having restarted your website, you can check in the phpinfo() page if the extension was loaded correcty:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/davide_mauri/image_73AF7BE2.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/davide_mauri/image_thumb_3DCA86C8.png" width="244" height="85" /&gt;&lt;/a&gt;&lt;/p&gt;              &lt;p&gt;I &lt;strong&gt;strongly &lt;/strong&gt;suggest to take a look at the help file that comes with the PHP SQL Server Drivers, so that you can start to get used to access SQL Server from PHP. In particular use the code shown in the &lt;/p&gt;  &lt;p&gt;“How to: Connect Using SQL Server Authentication”&lt;/p&gt;  &lt;p&gt;help article in order to create a .php page to test that your environment can correctly connect to SQL Server.&lt;/p&gt;  &lt;p&gt;Of course be sure to have at least the SQL Server Native Client installed on the web server, otherwise you won’t be able to connect to SQL Server from PHP.&lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.microsoft.com/en-us/download/details.aspx?id=29065" href="http://www.microsoft.com/en-us/download/details.aspx?id=29065"&gt;http://www.microsoft.com/en-us/download/details.aspx?id=29065&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;That’s it! You now have a PHP environment on you IIS 7 / 7.5 capable of using SQL Server as RDBMS.&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43244" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/davide_mauri/archive/tags/IIS/default.aspx">IIS</category><category domain="http://sqlblog.com/blogs/davide_mauri/archive/tags/PHP/default.aspx">PHP</category><category domain="http://sqlblog.com/blogs/davide_mauri/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>Wordpress and PHPBB on SQL Server</title><link>http://sqlblog.com/blogs/davide_mauri/archive/2012/05/07/wordpress-and-phpbb-on-sql-server.aspx</link><pubDate>Mon, 07 May 2012 14:12:18 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43239</guid><dc:creator>Davide Mauri</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;In the last months, in the spare time, I started to study PHP in order to use it on a Windows + SQL Server box. Why you would do such thing you may be wondering. The point is that Wordpress is actually, IMHO, the state of the art of a free CMS that must be used as the backend for a community site: it’s feature-rich, it has a *lot* of plugins and themes, it can be used to host blogs and to empower a “thematic” website. In my case I’d like to refresh the engine used to publish the Italian SQL Server User Group website.&lt;/p&gt;  &lt;p&gt;I’ve looked for a lot of alternatives in the .NET World, and I evaluated in the last year&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Umbraco &lt;/li&gt;    &lt;li&gt;DotNetNuke &lt;/li&gt;    &lt;li&gt;Community Server &lt;/li&gt;    &lt;li&gt;Orchard &lt;/li&gt;    &lt;li&gt;ScrewturnWiki &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For one reason or another, none of the mentioned platforms, which are great platforms BTW, was the right for us. We needed something&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Capable of managing a community portal with news, articles, events, calendars and so on &lt;/li&gt;    &lt;li&gt;Capable of managing the blogs of members, allowing the generation of new blog sub site on the fly &lt;/li&gt;    &lt;li&gt;Fully customizable with a minimum effort for the end user &lt;/li&gt;    &lt;li&gt;Enabled to use HTML5 and CSS3 &lt;/li&gt;    &lt;li&gt;Stable and Mature, with a good documentation and/or forum support &lt;/li&gt;    &lt;li&gt;Easy to be extended/modified adapted to our needs &lt;/li&gt;    &lt;li&gt;Compatible with MSN Live Writer &lt;/li&gt;    &lt;li&gt;Compatible with SQL Server &lt;/li&gt;    &lt;li&gt;Capable of hosting forums or capable of be integrated with a 3rd party forum platform &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;And at the end the platform that suits all our need is…Wordpress!&lt;/p&gt;  &lt;p&gt;Of course this decision bring some challenges in the game:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;I need to be sure that Wordpress can work *well* with SQL Server &lt;/li&gt;    &lt;li&gt;I need to integrate Wordpress with a forum software. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Luckily Microsoft has written a cool abstraction layer for Wordpress, that make it compatible with SQL Server. And, even more luckily, there is a mainstream forum solution, PHPBB, natively compatible with SQL Server.&lt;/p&gt;  &lt;p&gt;Of course not everything is as smooth as one would like it to be, so there are some “attention point” that one need to take into account when going in this way. And since there isn’t a lot of&amp;#160; documentation available on running Wordpress together with PHPBB on SQL Server, I though that writing some post can be helpful to the community. After all Wordpress and PHPBB are two *great* solution and having them available on SQL Server is something desirable in my opinion.&lt;/p&gt;  &lt;p&gt;So, in the next months, I’ll write a series of four (maybe five) posts to describe how to have a Wordpress + PHPBB on IIS + SQL Server solution up and running.&lt;/p&gt;  &lt;p&gt;Here’s the agenda of the next posts:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://sqlblog.com/blogs/davide_mauri/archive/2012/05/07/php-setup-for-iis-and-sql-server.aspx"&gt;PHP Setup for IIS and SQL Server&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Wordpress Installation &lt;/li&gt;    &lt;li&gt;PHPBB Installation &lt;/li&gt;    &lt;li&gt;Wordpress &amp;amp; PHPBB Login Integration &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I’ll hope you’ll enjoy the topics!&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43239" width="1" height="1"&gt;</description></item><item><title>Presenting at Seacoast SQL Server Users Group in New Hampshire 17 May 2012!</title><link>http://sqlblog.com/blogs/andy_leonard/archive/2012/05/07/presenting-at-seacoast-sql-server-users-group-in-new-hampshire-17-may-2012.aspx</link><pubDate>Mon, 07 May 2012 11:00:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43197</guid><dc:creator>andyleonard</dc:creator><slash:comments>0</slash:comments><description>I am honored to present Using BIML as an SSIS Design Patterns Engine to the Seacoast SQL Server Users Group 17 May 2012! This presentation is based on one of my favorite chapters in the upcoming book: SSIS Design Patterns scheduled for release this summer. If you find yourself in the Portsmouth New Hampshire area on the evening of 17 May, please drop by and introduce yourself. I am the fat guy with a fu. :{&amp;gt;...(&lt;a href="http://sqlblog.com/blogs/andy_leonard/archive/2012/05/07/presenting-at-seacoast-sql-server-users-group-in-new-hampshire-17-may-2012.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43197" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/andy_leonard/archive/tags/Presentations/default.aspx">Presentations</category><category domain="http://sqlblog.com/blogs/andy_leonard/archive/tags/SQL+Server+Community/default.aspx">SQL Server Community</category><category domain="http://sqlblog.com/blogs/andy_leonard/archive/tags/SSIS/default.aspx">SSIS</category></item><item><title>Registrations Open for SSAS Maestro in July 2012 #ssasmaestro #sass</title><link>http://sqlblog.com/blogs/marco_russo/archive/2012/05/07/registrations-open-for-ssas-maestro-in-july-2012-ssasmaestro-sas.aspx</link><pubDate>Mon, 07 May 2012 08:24:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43233</guid><dc:creator>Marco Russo (SQLBI)</dc:creator><slash:comments>4</slash:comments><description>&lt;p&gt;Registrations are now open for the &lt;a href="http://www.sqlbi.com/training/ssas-maestro"&gt;SSAS Maestro course&lt;/a&gt; in July 2012, which will take place in Milan (Italy).&lt;/p&gt;  &lt;p&gt;I introduced this course in a &lt;a href="http://ads.sqlblog.com/blogs/marco_russo/archive/2012/03/20/ssas-maestro-training-in-july-2012-ssasmaestro-ssas.aspx"&gt;previous blog post&lt;/a&gt; and I’m not going to repeat all the details here. I just want to highlight a few updates, the biggest one is related to the cost of the course. We received several feedback and cut some of the costs for reducing the fee. One of the consequences is that we will not include Tabular as part of the SSAS Maestro course, which will be dedicated only to Multidimensional. We’ll evaluate how to include Tabular in the future. As a result, the price is now 4500€ (reduced to 3500€ for students of a previous SSAS Maestro edition). This is not going to lower the overall value of the course and the price includes the complete evaluation process after the training.&lt;/p&gt;  &lt;p&gt;Another very good news is that &lt;a href="http://blog.kejser.org/"&gt;Thomas Kejser&lt;/a&gt; (from the &lt;a href="http://sqlcat.com/"&gt;SQLCAT&lt;/a&gt; team) will join me and Chris Webb teaching the class. This is another important contribution that adds value to the course: Thomas has been involved in development and deployment of TBs-sized cubes and discussions about scalability of SSAS cubes are an important part of the SSAS Maestro training.&lt;/p&gt;  &lt;p&gt;Please read &lt;a href="http://ads.sqlblog.com/blogs/marco_russo/archive/2012/03/20/ssas-maestro-training-in-july-2012-ssasmaestro-ssas.aspx"&gt;my previous post&lt;/a&gt; to get other details about the SSAS Maestro certification process. If you want to get more information and/or ask if you are a good candidate for SSAS Maestro certification, write to &lt;a title="ssasmaestro@sqlbi.com" href="mailto:ssasmaestro@sqlbi.com"&gt;ssasmaestro@sqlbi.com&lt;/a&gt; sending your CV/resume and a short description of your level of SSAS knowledge and experience. The seats are limited and it is important that students have the right prerequisites in terms of SSAS experience. When you are ready, you can register &lt;a href="http://www.sqlbi.com/courses/ssas-maestro-milan-jul2012/"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43233" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/marco_russo/archive/tags/Analysis+Services/default.aspx">Analysis Services</category><category domain="http://sqlblog.com/blogs/marco_russo/archive/tags/SSAS/default.aspx">SSAS</category></item><item><title>Principles of Modeling: Avoid Redundancy</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2012/05/05/principles-of-modeling-avoid-redundancy.aspx</link><pubDate>Sat, 05 May 2012 19:31:12 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43213</guid><dc:creator>Hugo Kornelis</dc:creator><slash:comments>0</slash:comments><description>In 1994, I learned a method for data modeling that is based on three principles. I immediately knew that these principles should embraced by anyone who does any data modeling or process modeling. Or almost any other job, for that matter. I have described these principles in three previous blog posts: the Jargon Principle , the Concreteness Principle , and the Reproducibility Principle . But I have later found that there are more principles and guidelines that are important to keep in mind when modeling....(&lt;a href="http://sqlblog.com/blogs/hugo_kornelis/archive/2012/05/05/principles-of-modeling-avoid-redundancy.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43213" width="1" height="1"&gt;</description></item><item><title>Decoding STATS_STREAM</title><link>http://sqlblog.com/blogs/joe_chang/archive/2012/05/05/decoding-stats-stream.aspx</link><pubDate>Sat, 05 May 2012 10:16:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43206</guid><dc:creator>jchang</dc:creator><slash:comments>2</slash:comments><description>Data distribution statistics is one of the foundations of the cost-based query optimizer in all modern database engines including SQL Server. From SQL Server 2005 on, most of the information displayed by DBCC SHOW_STATISTICS is kept in a binary field accessible with the STATS_STREAM clause. Back in SQL Server 2000, it was possible to modify system tables directly, including the sysindexes stat_blob field. At the time, I described a decode of the stat_blob field with the purpose of influence the execution...(&lt;a href="http://sqlblog.com/blogs/joe_chang/archive/2012/05/05/decoding-stats-stream.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43206" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/joe_chang/archive/tags/Statistics/default.aspx">Statistics</category></item><item><title>Execute T-SQL Across Listed Servers/Databases</title><link>http://sqlblog.com/blogs/merrill_aldrich/archive/2012/05/04/execute-t-sql-across-listed-servers-databases.aspx</link><pubDate>Fri, 04 May 2012 22:50:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43199</guid><dc:creator>merrillaldrich</dc:creator><slash:comments>3</slash:comments><description>Here’s a handy trick – if you have a SQL script, stored as a text file, and need to run it against an arbitrary list of different databases on different SQL Server instances, try a little PowerShell. There are a lot of ways to accomplish this task, but personally I like this one for its flexibility. First, make sure the SQL script does NOT include the common USE &amp;lt;database&amp;gt;. Generally that statement is your friend, but not in cases where a single script should work against multiple databases...(&lt;a href="http://sqlblog.com/blogs/merrill_aldrich/archive/2012/05/04/execute-t-sql-across-listed-servers-databases.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43199" width="1" height="1"&gt;</description></item><item><title>The Curious Case of the Optimizer that doesn’t</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2012/05/04/the-curious-case-of-the-optimizer-that-doesn-t.aspx</link><pubDate>Thu, 03 May 2012 22:13:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43164</guid><dc:creator>Hugo Kornelis</dc:creator><slash:comments>8</slash:comments><description>The optimizer is the part of SQL Server that takes your query and reorders and rearranges your query to find the optimal execution plan. In theory. In practice, that doesn’t always work out well. Often, the optimizer manages to come up with brilliant ways to execute a complex query very efficiently – but sometimes, it misses an option that appears to be so simple that you can only stare in utter amazement at the execution plan before going to the Connect site. Here is an example I recently ran into....(&lt;a href="http://sqlblog.com/blogs/hugo_kornelis/archive/2012/05/04/the-curious-case-of-the-optimizer-that-doesn-t.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43164" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/hugo_kornelis/archive/tags/Performance/default.aspx">Performance</category><category domain="http://sqlblog.com/blogs/hugo_kornelis/archive/tags/SQL+Server+2008/default.aspx">SQL Server 2008</category><category domain="http://sqlblog.com/blogs/hugo_kornelis/archive/tags/SQL+Server+2012/default.aspx">SQL Server 2012</category><category domain="http://sqlblog.com/blogs/hugo_kornelis/archive/tags/T-SQL/default.aspx">T-SQL</category></item><item><title>New version of SSDT Power Tools are available – but with a caveat</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2012/05/03/new-version-of-ssdt-power-tools-are-available-but-with-a-caveat.aspx</link><pubDate>Thu, 03 May 2012 20:12:07 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43163</guid><dc:creator>jamiet</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;A little over a month ago &lt;a href="http://blogs.msdn.com/b/ssdt/archive/2012/04/02/first-release-of-ssdt-power-tools.aspx" target="_blank"&gt;the first version of the SSDT Power Tools were made available&lt;/a&gt; bringing with them some much needed functionality – a replacement for Schema View called SQL Server Object Explorer.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_05131584.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_3C7926B2.png" width="274" height="420" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Along with the first release of the power tools came a promise that they would be updated on a regular cadence and, true to their word, an updated version (v1.1) is already available.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img src="https://p.twimg.com/Ar-5j5rCMAAgDg3.png:large" width="835" height="470" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If you have got v1.0 installed then you should automatically be notified about the update. However, an attempt to apply the update results in this little nasty:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_45F1E528.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_006CE4FD.png" width="387" height="248" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Here’s the full text of that error in case anyone happens to Bingle* for it:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Digital signature mismatch&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;The signature on the update version of 'SSDT Power Tools' does not match the signature on the installed version. Therefore, extension manager cannot install the update.        &lt;br /&gt;&lt;/em&gt;&lt;em&gt;If you trust the update, try the installation again after you install the installed version.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Now, according to &lt;a href="http://support.microsoft.com/kb/2581019" target="_blank"&gt;this KB article&lt;/a&gt; this isn’t an issue with the extension, it is actually an issue with the Extension Manager in Visual Studio 2010 Service Pack 1 hence the recommended course of action is to uninstall and then reinstall from the gallery&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_42FC8075.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_27E3B167.png" width="506" height="286" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I did this and it worked just fine.&lt;/p&gt;  &lt;p&gt;Of course, the only missing information is what is new in this update and a cursory search hasn’t uncovered anything. I suggest keeping an eye on the &lt;a href="http://blogs.msdn.com/b/ssdt/" target="_blank"&gt;SSDT blog&lt;/a&gt; to see if any such news transpires.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;*Bingle – to search using Google or Bing. I first saw “Bingle” in an email a few weeks ago from Glenn Berry (&lt;a href="http://sqlserverperformance.wordpress.com/" target="_blank"&gt;blog&lt;/a&gt; |&lt;a href="http://twitter.com/glennalanberry" target="_blank"&gt;twitter&lt;/a&gt;) and it rather amused me so I’m adopting it for the foreseeable future &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://sqlblog.com/blogs/jamie_thomson/wlEmoticon-smile_4DF2ABA7.png" /&gt;&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43163" width="1" height="1"&gt;</description></item><item><title>Build Your Own Microsoft Operations Manager Pack</title><link>http://sqlblog.com/blogs/kevin_kline/archive/2012/05/03/build-your-own-microsoft-operations-manager-pack.aspx</link><pubDate>Thu, 03 May 2012 15:25:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43125</guid><dc:creator>KKline</dc:creator><slash:comments>0</slash:comments><description>Want to develop your own Operations Manager Management Pack? Here's how....(&lt;a href="http://sqlblog.com/blogs/kevin_kline/archive/2012/05/03/build-your-own-microsoft-operations-manager-pack.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43125" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/kevin_kline/archive/tags/Administration/default.aspx">Administration</category><category domain="http://sqlblog.com/blogs/kevin_kline/archive/tags/Architecture/default.aspx">Architecture</category><category domain="http://sqlblog.com/blogs/kevin_kline/archive/tags/Automation/default.aspx">Automation</category><category domain="http://sqlblog.com/blogs/kevin_kline/archive/tags/Infrastructure/default.aspx">Infrastructure</category><category domain="http://sqlblog.com/blogs/kevin_kline/archive/tags/Management/default.aspx">Management</category><category domain="http://sqlblog.com/blogs/kevin_kline/archive/tags/On-line+Resources/default.aspx">On-line Resources</category><category domain="http://sqlblog.com/blogs/kevin_kline/archive/tags/System+Center/default.aspx">System Center</category></item><item><title>Parallel Execution Plans Suck</title><link>http://sqlblog.com/blogs/paul_white/archive/2012/05/03/parallel-row-goals-gone-rogue.aspx</link><pubDate>Wed, 02 May 2012 17:57:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:43147</guid><dc:creator>Paul White</dc:creator><slash:comments>7</slash:comments><description>&lt;p align="left"&gt;&lt;i&gt;Summary: A deep dive into SQL Server parallelism, and a potential performance problem with parallel plans that use TOP.&lt;/i&gt;&lt;/p&gt;  &lt;p align="left"&gt;There was an interesting &lt;a href="http://dba.stackexchange.com/questions/7233/inaccurate-actual-row-counts-in-parallel-plan" target="_blank"&gt;question&lt;/a&gt; asked by &lt;a href="http://uk.linkedin.com/in/markstoreysmith" target="_blank"&gt;Mark Storey-Smith&lt;/a&gt; on &lt;a href="http://dba.stackexchange.com/"&gt;dba.stackexchange.com&lt;/a&gt; back in October 2011.&amp;#160; He was looking at the execution plan for a query that counts a million rows from a &lt;a href="http://www.sqlmag.com/article/sql-server/virtual-auxiliary-table-of-numbers"&gt;virtual auxiliary table of numbers&lt;/a&gt;.&amp;#160; The query below is a slightly-modified version of the one in the original post:&lt;/p&gt;  &lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:400px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;WITH&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N1 (n) &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    (&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#008000;"&gt;-- 10 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    ),&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N2 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; L.n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N1 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; L &lt;span style="color:#0000ff;"&gt;CROSS&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; N1 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; R), &lt;span style="color:#008000;"&gt;-- 100 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N3 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; L.n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N2 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; L &lt;span style="color:#0000ff;"&gt;CROSS&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; N2 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; R), &lt;span style="color:#008000;"&gt;-- 10,000 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N4 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; L.n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N3 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; L &lt;span style="color:#0000ff;"&gt;CROSS&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; N3 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; R), &lt;span style="color:#008000;"&gt;-- 100,000,000 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N5 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; L.n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N4 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; L &lt;span style="color:#0000ff;"&gt;CROSS&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; N1 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; R), &lt;span style="color:#008000;"&gt;-- 1,000,000,000 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N6 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    (&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TOP&lt;/span&gt; (1000000) n&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N5&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    )&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    COUNT_BIG(*)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N6&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;OPTION&lt;/span&gt; (RECOMPILE, MAXDOP 1);&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p align="left"&gt;This particular virtual numbers table is capable of producing up to a (&lt;a href="http://en.wikipedia.org/wiki/Billion"&gt;short-scale&lt;/a&gt;) billion rows, via a number of cross joins, but the final common table expression N6 limits it to one million with the TOP clause.&amp;#160; The query plan is just a sequence of cross joins of the ten in-memory rows defined by the first common table expression, N1 (click to enlarge):&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_7B6BCF68.png" target="_blank"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="One million row serial quey plan" border="0" alt="One million row serial quey plan" src="http://sqlblog.com/blogs/paul_white/image_thumb_38AC8430.png" width="660" height="98" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;As usual, the Constant Scan operator is used to generate rows in memory without accessing a physical table, but this one has an interesting property: the ‘virtual table’ contains ten rows, but &lt;b&gt;no columns&lt;/b&gt;.&amp;#160; The query itself only counts rows, it does nothing at all with any column in those rows, and the optimizer contains logic to only project columns that are needed later in the query plan.&amp;#160; If you look at the query plan in SSMS or SQL Sentry Plan Explorer, you will see that the Constant Scans have a blank output columns list; they project no columns at all.&lt;/p&gt;

&lt;h3 align="left"&gt;Execution Plans Suck&lt;/h3&gt;

&lt;p align="left"&gt;The plan above does illustrate an important concept in plan-reading: &lt;b&gt;execution plans start executing at the left-most node&lt;/b&gt;.&amp;#160; People are often told to read execution plans from the top-right, and that is fine if you just want to follow the flow of data – so long as you bear in mind that the flow of program control starts at the root (far left).&lt;/p&gt;

&lt;p align="left"&gt;Rob Farley (&lt;a href="http://sqlblog.com/blogs/rob_farley"&gt;blog&lt;/a&gt; | &lt;a href="https://twitter.com/#!/rob_farley"&gt;twitter&lt;/a&gt;) sums this up by saying “execution plans suck”; a reference to the fact that rows are pulled up the tree by parent operators requesting rows, &lt;b&gt;one at a time&lt;/b&gt;, from the its child operator(s).&amp;#160; Query execution follows a &lt;b&gt;demand-based pipeline model&lt;/b&gt; (except in batch mode in parallel 2012 column-store plans, but that is a tangent we will not be pursuing today).&amp;#160; I’m not going to labour the point, but if you are interested to understand this better, take a look at my &lt;a href="http://sqlblog.com/blogs/paul_white/archive/2010/08/05/iterators-query-plans-and-why-they-run-backwards.aspx"&gt;previous post&lt;/a&gt; on the topic, or Brad Schulz’s &lt;a href="http://bradsruminations.blogspot.co.nz/2010/11/second-in-life-of-query-operator.html"&gt;entertaining overview&lt;/a&gt;.&lt;/p&gt;

&lt;p align="left"&gt;Let’s look at the execution plan (with runtime statistics) changing the TOP specification from one million to one hundred to make it easier to see what’s going on:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_4461CB62.png" target="_blank"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="TOP 100 Plan" border="0" alt="TOP 100 Plan" src="http://sqlblog.com/blogs/paul_white/image_thumb_6187736C.png" width="640" height="146" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;I’m just showing part of the plan for clarity.&amp;#160; There are another four Constant Scans off to the right that all produce one row.&amp;#160; If query plans really did start executing at the top right, we would expect one row from the right-most Constant Scan, ten rows from its parent, and one hundred at the next operator up the tree (working right to left).&amp;#160; As it is, the expected pattern (one, then ten, then one hundred) appears closest to the Top operator.&amp;#160; This only makes sense if a row at a time is sucked up the plan from the root.&amp;#160; The pipelined (row-by-row) model also explains why execution stops after 100 rows; the Top operator in the plan simply stops requesting a new row from its immediate child at that point.&lt;/p&gt;

&lt;h3 align="left"&gt;The Question&lt;/h3&gt;

&lt;p align="left"&gt;Back to the main thrust of today’s post.&amp;#160; The question arose when Mark ran his query with parallelism enabled:&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:400px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;WITH&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N1 (n) &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    (&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#008000;"&gt;-- 10 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    ),&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N2 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; L.n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N1 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; L &lt;span style="color:#0000ff;"&gt;CROSS&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; N1 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; R), &lt;span style="color:#008000;"&gt;-- 100 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N3 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; L.n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N2 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; L &lt;span style="color:#0000ff;"&gt;CROSS&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; N2 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; R), &lt;span style="color:#008000;"&gt;-- 10,000 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N4 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; L.n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N3 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; L &lt;span style="color:#0000ff;"&gt;CROSS&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; N3 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; R), &lt;span style="color:#008000;"&gt;-- 100,000,000 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N5 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; L.n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N4 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; L &lt;span style="color:#0000ff;"&gt;CROSS&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; N1 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; R), &lt;span style="color:#008000;"&gt;-- 1,000,000,000 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N6 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    (&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TOP&lt;/span&gt; (1000000) n&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N5&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    )&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    COUNT_BIG(*)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N6&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;OPTION&lt;/span&gt; (RECOMPILE, MAXDOP 2);&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p align="left"&gt;That produces an actual execution plan like this (click to enlarge):&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_49A08C46.png" target="_blank"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="Parallel Top One Million" border="0" alt="Parallel Top One Million" src="http://sqlblog.com/blogs/paul_white/image_thumb_624FB389.png" width="644" height="66" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;The question relates to the actual number of rows shown entering and leaving the Gather Streams exchange operator:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_388C3896.png" target="_blank"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="Gather Streams Exchange" border="0" alt="Gather Streams Exchange" src="http://sqlblog.com/blogs/paul_white/image_thumb_360306D8.png" width="367" height="88" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;As expected, one million rows leave the exchange operator, but the plan shows &lt;b&gt;1,004,588&lt;/b&gt; rows entering it.&amp;#160; So the question is, are the row counts wrong, or if not, where did the rows go?&lt;/p&gt;

&lt;h3 align="left"&gt;The Answer&lt;/h3&gt;

&lt;p align="left"&gt;As you may know, the answer lies in the fact that exchanges &lt;a href="http://www.simple-talk.com/sql/learn-sql-server/understanding-and-using-parallelism-in-sql-server/"&gt;contain buffers&lt;/a&gt;.&amp;#160; For efficiency reasons, rows are not passed across threads one by one as in the normal model discussed above.&amp;#160; Instead, producer threads (on the right side of the exchange operator) pack rows one at a time into packets, and push completed packets across the &lt;a href="http://blogs.msdn.com/b/craigfr/archive/2006/10/25/the-parallelism-operator-aka-exchange.aspx"&gt;exchange&lt;/a&gt;.&amp;#160; Consumer thread(s) on the left side of the exchange retrieve rows one at a time from the current packet on demand, re-establishing the demand-based pipeline model.&amp;#160; The internal class name for the packets, by the way, is Class eXchange PACKET – which gives us the familiar CXPACKET moniker.&lt;/p&gt;

&lt;p align="left"&gt;Exploring the detail at little more, we can see from the execution plan that the two independent producer threads to the right of the exchange pack a total of 499,225 + 505,363 = &lt;b&gt;1,004,588&lt;/b&gt; rows into packets, and the single consumer thread (thread zero) retrieves just the one million rows needed by the Top operator:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_30A54DC8.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="Per Thread Row Counts" border="0" alt="Per Thread Row Counts" src="http://sqlblog.com/blogs/paul_white/image_thumb_4064E2CC.png" width="457" height="116" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;So, the actual row counts shown on the execution plan are correct, and the ‘missing rows’ are accounted for by rows that were added to packets but not ultimately needed by the consumer.&amp;#160; After the one millionth row is passed by the Top to the Stream Aggregate (and remember all these things happen one row at a time), the next time the Top gets control, it starts the process of shutting down the pipeline below it, rather than asking the Gather Streams exchange for another row.&amp;#160; Glossing over the finer details a little, instead of the Top calling a &lt;strong&gt;GetRow&lt;/strong&gt;() method on the &lt;i&gt;Gather Streams&lt;/i&gt; iterator, it calls a &lt;strong&gt;Close&lt;/strong&gt;() method instead.&lt;/p&gt;

&lt;h3 align="left"&gt;SQL Server 2008+&lt;/h3&gt;

&lt;p align="left"&gt;On SQL Server 2005 that is the end of the story.&amp;#160; On SQL Server 2008 and later (including 2012), there is more.&amp;#160; Let’s run the query one more time, but this time with a degree of parallelism of three, rather than two.&amp;#160; Sometimes, we will get a plan that contains this sort of row count arrangement at the Gather Streams:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_6BC903C6.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="DOP 3 Gather Streams" border="0" alt="DOP 3 Gather Streams" src="http://sqlblog.com/blogs/paul_white/image_thumb_693FD208.png" width="354" height="95" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;Much the same as before, a few thousand extra rows are processed by the producer threads than are ultimately needed by the consumer.&amp;#160; That’s fine, of course, the threads in a parallel plan execute independently, so there are bound to be small timing differences that lead to this sort of effect.&amp;#160; Every so often, however, executing this query on SQL Server 2008 or above will produce a result like this:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_51C51DD7.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="Monster Row Count" border="0" alt="Monster Row Count" src="http://sqlblog.com/blogs/paul_white/image_thumb_4F3BEC19.png" width="363" height="92" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;Whoa.&amp;#160; Nearly &lt;b&gt;335 million rows&lt;/b&gt; entering the exchange – and the query now runs for &lt;b&gt;50 seconds&lt;/b&gt; or so, having run consistently for around &lt;b&gt;200ms&lt;/b&gt; previously.&amp;#160; Looking at the per-thread actual row counts is revealing:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_4CB2BA5B.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="Monster Per Thread" border="0" alt="Monster Per Thread" src="http://sqlblog.com/blogs/paul_white/image_thumb_7163D1D2.png" width="546" height="140" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;If everything were perfectly balanced, we might expect each of the three producer threads to process around 333,000 rows.&amp;#160; Indeed, thread 1 and thread 2 are in this ballpark area, but thread 3 ground through &lt;b&gt;334 million rows&lt;/b&gt; on its own!&amp;#160; I should mention that there is nothing special about thread 3 (you are as likely to find the huge row count on thread 1 or thread 2, the labels are arbitrary).&amp;#160; Indeed, the problem can occur on any or all threads, as a second example run at DOP 3 shows below:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_68279691.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="DOP 3 Second Example" border="0" alt="DOP 3 Second Example" src="http://sqlblog.com/blogs/paul_white/image_thumb_21CA307C.png" width="368" height="95" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_1F40FEBE.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="DOP 3 Per Thread Row Counts 2" border="0" alt="DOP 3 Per Thread Row Counts 2" src="http://sqlblog.com/blogs/paul_white/image_thumb_5CEDE67A.png" width="565" height="140" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;This time two threads went rogue, resulting in over &lt;b&gt;667 million rows&lt;/b&gt; being processed in a total execution time of &lt;b&gt;67 seconds&lt;/b&gt;.&lt;/p&gt;

&lt;h3 align="left"&gt;Parallelism Problems?&lt;/h3&gt;

&lt;p align="left"&gt;There are other parallelism (exchange) operators in the plan, though we have concentrated only on the final Gather Streams operator so far.&amp;#160; By the way, Gather Streams is also known as a &lt;b&gt;Start Parallelism&lt;/b&gt; operator – a name that might surprise you since it seems to mark the &lt;b&gt;end&lt;/b&gt; of parallelism in the plan, rather than the start.&amp;#160; Remember that execution plans suck.&amp;#160; The ‘final’ Gather Streams is in fact the first operator to start executing, and it is responsible for &lt;b&gt;starting the parallel workers&lt;/b&gt; and attaching them to the threads that were reserved for this plan at the very start of execution.&amp;#160; Anyway, I digress.&amp;#160; Let’s look at the next exchange in the plan – reading left to right of course.&amp;#160; This is a &lt;i&gt;Repartition Streams&lt;/i&gt; exchange operating in &lt;i&gt;Round Robin&lt;/i&gt; distribution mode:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_5A64B4BC.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="Repartition Streams" border="0" alt="Repartition Streams" src="http://sqlblog.com/blogs/paul_white/image_thumb_30A139C9.png" width="570" height="262" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;This shows that 1,000 rows arriving on the producer side of the exchange, and a total of 668 on the consumer side.&amp;#160; Not shown in the diagram above, the producer side has 340 rows on thread 1, and 330 rows on each of thread 2 and thread 3.&amp;#160; Note that these are &lt;b&gt;not the same threads&lt;/b&gt; as the ones we saw numbered the same way before.&amp;#160; The numbering scheme is restarted for each independent parallel zone in the plan (and zones are bounded by a parallelism operator of one sort or another).&amp;#160; Anyway, the point is that the rows are pretty evenly distributed on the producer side of the exchange.&lt;/p&gt;

&lt;p align="left"&gt;On the consumer side (row counts illustrated above), things are rather different.&amp;#160; Thread 1 (in this zone) processes 334 rows, thread 2 gets 333, and thread 3 gets only one.&amp;#160; Now these &lt;b&gt;are&lt;/b&gt; the same threads as shown in the 667 million row diagram.&amp;#160; I mentioned that &lt;b&gt;parallel zones&lt;/b&gt; are bordered by parallelism operators; the current zone is bordered by the Repartition Streams on its right side, and by the Gather Streams on its left.&amp;#160; The same three threads are &lt;b&gt;consumers&lt;/b&gt; at the &lt;i&gt;Repartition Streams&lt;/i&gt;, and &lt;b&gt;producers&lt;/b&gt; at the &lt;i&gt;Gather Streams&lt;/i&gt; operator:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_2E1E64BA.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="Consumer Producer Branch" border="0" alt="Consumer Producer Branch" src="http://sqlblog.com/blogs/paul_white/image_thumb_1E2F1FF6.png" width="660" height="205" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;There is a clear relationship between the thread row counts at the consumer side of the Repartition Streams (334, 333, and 1 row) and the row counts at the producer side of the Gather Streams (334 million, 333 million, 338,614 rows).&amp;#160; The two problematic threads have multiplied their row counts by a factor of one million – precisely the effect of the &lt;b&gt;six cross joins&lt;/b&gt; in this parallelism zone.&amp;#160; The Constant Scan virtual tables contain ten rows each, and multiplying by ten, six times over, gives a factor of one million.&lt;/p&gt;

&lt;h3 align="left"&gt;Rogue Row Goals&lt;/h3&gt;

&lt;p align="left"&gt;Thread 3 in the example above ends up processing 338,614 rows.&amp;#160; This number has no special significance, except it shows that this thread did not run this portion of the plan to completion.&amp;#160; If it had, the single row it started with would have ended up as one million rows by the time it had been cross-joined six times with the ten-row Constant Scan table.&lt;/p&gt;

&lt;p align="left"&gt;This is the &lt;b&gt;row goal&lt;/b&gt; in action (if you need a details on exactly what a row goal is, please see &lt;a href="http://sqlblog.com/blogs/paul_white/archive/2010/08/18/inside-the-optimiser-row-goals-in-depth.aspx"&gt;my previous post&lt;/a&gt;).&amp;#160; Essentially, though, things like a TOP operator or a FAST n hint set a row goal.&amp;#160; Plans normally run to completion, but row goals modify this, producing a plan that tries to optimize for a &lt;b&gt;certain number of rows&lt;/b&gt; rather than the full potential set.&amp;#160; The TOP operator is even more special.&amp;#160; As discussed briefly before, TOP can bring execution to an early end – instead of continuing to ask for rows from its child iterator, it calls the &lt;b&gt;Close()&lt;/b&gt; method instead.&amp;#160; This call filters down the tree, and execution comes to an early end.&amp;#160; (Strictly, row goals affect optimizer choices and plan costing rather than being associated with the early end of execution, but I like the phrase ‘rogue row goal’).&lt;/p&gt;

&lt;p align="left"&gt;So, thread 3 did not run to completion – it responded to the early Close() call and only processed 338 thousand of the one million rows it could have produced if left alone.&amp;#160; Threads 1 and 2 never received the Close() call, or chose to ignore it.&amp;#160; These two rogues went on to process their full potential row set – 667 million rows – despite the fact that the TOP had seen the million rows it needed and was waiting for operations elsewhere in the parallel plan to stop.&amp;#160; We can see this by looking at the &lt;a href="http://msdn.microsoft.com/en-us/library/ms188743.aspx"&gt;sys.dm_os_waiting_tasks&lt;/a&gt; DMV while the long-running query is executing:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_06DDBED6.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="e_waitPortClose" border="0" alt="e_waitPortClose" src="http://sqlblog.com/blogs/paul_white/image_thumb_1D505D5D.png" width="662" height="173" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;The output is split across two lines for readability, and shows &lt;b&gt;execution context zero&lt;/b&gt; blocked on a &lt;b&gt;CXPACKET&lt;/b&gt; wait by both execution context 1 and execution context 3.&amp;#160; Execution context zero is always thread zero – the so-called coordinator thread that runs the serial part of the execution plan to the left of the left-most &lt;i&gt;Gather Streams&lt;/i&gt; operator.&amp;#160; Put another way, context zero always runs the part of the plan &lt;i&gt;before&lt;/i&gt; (reading left to right) the &lt;em&gt;Start Parallelism&lt;/em&gt; operator (and therefore always runs a serial plan).&lt;/p&gt;

&lt;p align="left"&gt;OK, so CXPACKET means the thread is involved in a parallelism-related wait.&amp;#160; The extra detail in the &lt;i&gt;resource_description&lt;/i&gt; column tells us that the wait is occurring at the node id 2.&amp;#160; Checking the execution plan, we see that node 2 is indeed the Gather Streams exchange:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_2905A48F.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="Node 2" border="0" alt="Node 2" src="http://sqlblog.com/blogs/paul_white/image_thumb_2E741533.png" width="365" height="102" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;The wait type of &lt;i&gt;e_waitPortClose&lt;/i&gt; means the consumer is waiting for the port to close.&amp;#160; If you are wondering what a &lt;b&gt;port&lt;/b&gt; is in this context, I will just say the parallelism architecture is more complex than just &lt;b&gt;CXPACKET&lt;/b&gt; – the wiring includes a &lt;b&gt;CXPort&lt;/b&gt; class, a &lt;b&gt;CXPipe&lt;/b&gt; class, a &lt;b&gt;CXTransLocal&lt;/b&gt; (local transport) class and a &lt;b&gt;CXTransRemote&lt;/b&gt; class (for the Parallel Data Warehouse edition).&amp;#160; There is also a linked map structure that shows how the various pipes, ports, and transports connect together.&amp;#160; Closing the port is one step in shutting down part of a parallel plan which is running on the other side of an exchange (via a transport, pipe, and port).&amp;#160; The stack trace below shows thread zero waiting for the port to close:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_69057809.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="Stack Trace" border="0" alt="Stack Trace" src="http://sqlblog.com/blogs/paul_white/image_thumb_7FE44985.png" width="536" height="217" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;The important things are that (a) this problem &lt;b&gt;does not occur&lt;/b&gt; in SQL Server 2005; and (b) a number of changes were made to the internal parallelism implementation in SQL Server 2008.&amp;#160; These changes seem to have introduced a bug, where the consumer can wait for the port to close, but one or more producers either ignore the request, or fail to check for it, and go on to process the whole potential result set instead of stopping early.&lt;/p&gt;

&lt;h3 align="left"&gt;Not Just Nested Loops&lt;/h3&gt;

&lt;p align="left"&gt;Fellow SQLblogger Joe Chang (&lt;a href="http://sqlblog.com/blogs/joe_chang/"&gt;blog&lt;/a&gt;) suggested in the comments that this problem may only occur with parallel nested loops joins.&amp;#160; The script below reproduces the problem with parallel hash joins:&lt;/p&gt;

&lt;div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 1px solid;padding-bottom:4px;line-height:12pt;background-color:#f4f4f4;margin:20px 0px 10px;padding-left:4px;width:97.5%;padding-right:4px;font-family:'Courier New', courier, monospace;direction:ltr;max-height:800px;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px;" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;WITH&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N1 (n) &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    (&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#008000;"&gt;-- 10 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 &lt;span style="color:#0000ff;"&gt;UNION&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ALL&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    ),&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N2 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; L.n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N1 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; L &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; N1 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; R &lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt; L.n % 1 = R.n % 1), &lt;span style="color:#008000;"&gt;-- 100 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N3 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; L.n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N2 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; L &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; N2 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; R &lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt; L.n % 1 = R.n % 1), &lt;span style="color:#008000;"&gt;-- 10,000 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N4 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; L.n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N3 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; L &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; N3 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; R &lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt; L.n % 1 = R.n % 1), &lt;span style="color:#008000;"&gt;-- 100,000,000 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N5 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; L.n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N4 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; L &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; N1 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; R &lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt; L.n % 1 = R.n % 1), &lt;span style="color:#008000;"&gt;-- 1,000,000,000 rows&lt;/span&gt;&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    N6 &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    (&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TOP&lt;/span&gt; (1000000) n&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;        &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N5&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    )&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; &lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;    COUNT_BIG(*)&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:white;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; N6&lt;/pre&gt;


    &lt;pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;background-color:#f4f4f4;margin:0em;border-left-style:none;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;border-right-style:none;font-size:8pt;overflow:visible;padding-top:0px;"&gt;&lt;span style="color:#0000ff;"&gt;OPTION&lt;/span&gt; (RECOMPILE, MAXDOP 4, QUERYTRACEON 8649);&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p align="left"&gt;The full execution plan is rather large, but the key part is shown below (click to enlarge):&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_34C9C4C4.png" target="_blank"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="parallel hash join plan" border="0" alt="parallel hash join plan" src="http://sqlblog.com/blogs/paul_white/image_thumb_3FA6A60C.png" width="660" height="274" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;Yes, that is &lt;strong&gt;700 million rows&lt;/strong&gt; entering the Gather Streams exchange (click to enlarge):&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/image_1576F824.png" target="_blank"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="parallel hash row counts" border="0" alt="parallel hash row counts" src="http://sqlblog.com/blogs/paul_white/image_thumb_52B7ACEB.png" width="644" height="229" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;The bug does not occur in every query plan with Top and parallelism, but the choice of nested loops join is not the cause.&lt;/p&gt;

&lt;h3 align="left"&gt;Final Thoughts&lt;/h3&gt;

&lt;p align="left"&gt;The potential for poor performance and excessive processor usage here is obvious; and the chance of hitting the race condition gets &lt;b&gt;worse&lt;/b&gt; at higher DOP.&amp;#160; With eight threads per parallel zone (DOP 8), I hit this issue almost every time on SQL Server 2008, 2008 R2, and 2012.&amp;#160; Because this behaviour does not occur on SQL Server 2005, but does on 2008 and later, I have filed this as a bug on Connect:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="https://connect.microsoft.com/SQLServer/feedback/details/740234/poor-performance-with-parallelism-and-top"&gt;https://connect.microsoft.com/SQLServer/feedback/details/740234/poor-performance-with-parallelism-and-top&lt;/a&gt;&lt;/p&gt;

&lt;h4 align="left"&gt;Further Reading:&lt;/h4&gt;

&lt;p align="left"&gt;&lt;a href="http://sqlblog.com/blogs/paul_white/archive/2010/08/05/iterators-query-plans-and-why-they-run-backwards.aspx"&gt;http://sqlblog.com/blogs/paul_white/archive/2010/08/05/iterators-query-plans-and-why-they-run-backwards.aspx&lt;/a&gt; 

  &lt;br /&gt;&lt;a title="http://bradsruminations.blogspot.co.nz/2010/11/second-in-life-of-query-operator.html" href="http://bradsruminations.blogspot.co.nz/2010/11/second-in-life-of-query-operator.html"&gt;http://bradsruminations.blogspot.co.nz/2010/11/second-in-life-of-query-operator.html&lt;/a&gt; 

  &lt;br /&gt;&lt;a title="http://www.simple-talk.com/sql/learn-sql-server/understanding-and-using-parallelism-in-sql-server/" href="http://www.simple-talk.com/sql/learn-sql-server/understanding-and-using-parallelism-in-sql-server"&gt;http://www.simple-talk.com/sql/learn-sql-server/understanding-and-using-parallelism-in-sql-server&lt;/a&gt; 

  &lt;br /&gt;&lt;a title="http://blogs.msdn.com/b/craigfr/archive/2006/10/25/the-parallelism-operator-aka-exchange.aspx" href="http://blogs.msdn.com/b/craigfr/archive/2006/10/25/the-parallelism-operator-aka-exchange.aspx"&gt;http://blogs.msdn.com/b/craigfr/archive/2006/10/25/the-parallelism-operator-aka-exchange.aspx&lt;/a&gt; 

  &lt;br /&gt;&lt;a title="http://sqlblog.com/blogs/paul_white/archive/2010/08/18/inside-the-optimiser-row-goals-in-depth.aspx" href="http://sqlblog.com/blogs/paul_white/archive/2010/08/18/inside-the-optimiser-row-goals-in-depth.aspx"&gt;http://sqlblog.com/blogs/paul_white/archive/2010/08/18/inside-the-optimiser-row-goals-in-depth.aspx&lt;/a&gt;&lt;/p&gt;

&lt;p align="left"&gt;© 2012 Paul White 
  &lt;br /&gt;Twitter: &lt;a href="http://twitter.com/SQL_Kiwi"&gt;@SQL_Kiwi&lt;/a&gt; (with an underscore) 

  &lt;br /&gt;Email: &lt;a href="mailto:SQLkiwi@gmal.com"&gt;SQLkiwi@gmal.com&lt;/a&gt; (no underscore)&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=43147" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/paul_white/archive/tags/Internals/default.aspx">Internals</category><category domain="http://sqlblog.com/blogs/paul_white/archive/tags/Parallelism/default.aspx">Parallelism</category><category domain="http://sqlblog.com/blogs/paul_white/archive/tags/Performance/default.aspx">Performance</category><category domain="http://sqlblog.com/blogs/paul_white/archive/tags/Query+Plans/default.aspx">Query Plans</category><category domain="http://sqlblog.com/blogs/paul_white/archive/tags/Top/default.aspx">Top</category></item></channel></rss>
