<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Adam Machanic</title><subtitle type="html">Adam Machanic, SQL Server Practice Lead for The Pythian Group, shares his experiences with programming, performance tuning, and optimizing SQL Server 2000, 2005, and 2008, in conjunction with related technologies such as .NET.</subtitle><id>http://sqlblog.com/blogs/adam_machanic/atom.aspx</id><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/default.aspx" /><link rel="self" type="application/atom+xml" href="http://sqlblog.com/blogs/adam_machanic/atom.aspx" /><generator uri="http://communityserver.org" version="2.1.61129.1">Community Server</generator><updated>2007-08-14T09:29:00Z</updated><entry><title>[New England] NESQL Special Meeting, Featuring Craig Freedman</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2008/05/02/new-england-nesql-special-meeting-featuring-craig-freedman.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2008/05/02/new-england-nesql-special-meeting-featuring-craig-freedman.aspx</id><published>2008-05-02T17:38:00Z</published><updated>2008-05-02T17:38:00Z</updated><content type="html">&lt;p&gt;Next Thursday, May 8, the &lt;a href="http://nesql.org/"&gt;New England SQL Server Users Group&lt;/a&gt; will have a special meeting, featuring &lt;a href="http://blogs.msdn.com/craigfr/"&gt;Craig Freedman&lt;/a&gt; from the SQL Server development team.&amp;nbsp; Craig is The Man when it comes to query optimizer internals, and wrote an incredibly detailed chapter on the topic for &lt;a href="http://www.amazon.com/dp/0735621969"&gt;"Inside SQL Server 2005: Query Tuning and Optimization"&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;At the meeting next week, Craig will discuss some of what he talked about in the chapter, including the basics of how the query processor works and what iterators are.&amp;nbsp; He'll cover the various operators you'll commonly see in query plans, and describe how they actually work internally.&amp;nbsp; &lt;/p&gt;&lt;p&gt;This should be a great meeting, and we expect it to be very well attended.&amp;nbsp; In order to help us figure out food and drink, in addition to securing enough chairs for the meeting room, &lt;b&gt;we need you to RSVP if you're planning to attend&lt;/b&gt;.&amp;nbsp; In order to RSVP, &lt;a href="http://nesql.org/SignUp/tabid/96/Default.aspx"&gt;sign up for our mailing list&lt;/a&gt;.&amp;nbsp; I will send out an e-mail next Tuesday, and you can RSVP by replying to it.&amp;nbsp; Only attendees who RSVP will be eligible for our prize draw at the end of the night, so make sure to sign up for our list by Monday in order to guarantee that you don't get left out.&lt;/p&gt;&lt;p&gt;We would like to thank &lt;a href="http://www.red-gate.com/"&gt;Red Gate Software&lt;/a&gt;, who made a very generous donation to the group that allowed us to have this special meeting.&amp;nbsp; Red Gate makes some of my favorite SQL Server tools and provides a huge amount of community support in the SQL Server and .NET space, and we hope that you will give their products a try.&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=[New England] NESQL Special Meeting, Featuring Craig Freedman&amp;amp;body=Seen on SQLblog.com: %0A%0A%09[New England] NESQL Special Meeting, Featuring Craig Freedman%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2008/05/02/new-england-nesql-special-meeting-featuring-craig-freedman.aspx" target="_blank" title = "Email [New England] NESQL Special Meeting, Featuring Craig Freedman"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/05/02/new-england-nesql-special-meeting-featuring-craig-freedman.aspx&amp;amp;title=%5bNew+England%5d+NESQL+Special+Meeting%2c+Featuring+Craig+Freedman" target="_blank" title = "Submit [New England] NESQL Special Meeting, Featuring Craig Freedman to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/05/02/new-england-nesql-special-meeting-featuring-craig-freedman.aspx&amp;amp;phase=2" target="_blank" title = "Submit [New England] NESQL Special Meeting, Featuring Craig Freedman to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/05/02/new-england-nesql-special-meeting-featuring-craig-freedman.aspx&amp;amp;title=%5bNew+England%5d+NESQL+Special+Meeting%2c+Featuring+Craig+Freedman" target="_blank" title = "Submit [New England] NESQL Special Meeting, Featuring Craig Freedman to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/05/02/new-england-nesql-special-meeting-featuring-craig-freedman.aspx&amp;amp;title=%5bNew+England%5d+NESQL+Special+Meeting%2c+Featuring+Craig+Freedman" target="_blank" title = "Submit [New England] NESQL Special Meeting, Featuring Craig Freedman to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2008/05/02/new-england-nesql-special-meeting-featuring-craig-freedman.aspx&amp;amp;title=%5bNew+England%5d+NESQL+Special+Meeting%2c+Featuring+Craig+Freedman&amp;amp;;top=1" target="_blank" title = "Add [New England] NESQL Special Meeting, Featuring Craig Freedman to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=6600" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="New England" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/New+England/default.aspx" /><category term="nesql" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/nesql/default.aspx" /><category term="query processing" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/query+processing/default.aspx" /><category term="red gate" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/red+gate/default.aspx" /></entry><entry><title>[OT] SQLTeach: Almost Here</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2008/04/24/ot-sqlteach-almost-here.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2008/04/24/ot-sqlteach-almost-here.aspx</id><published>2008-04-25T00:15:00Z</published><updated>2008-04-25T00:15:00Z</updated><content type="html">&lt;p&gt;I was just reviewing my calendar for the next several weeks and noticed that 
the Toronto &lt;a href="http://www.sqlteach.com/"&gt;SQLTeach &lt;/a&gt;conference is now 
only a few weeks away.&amp;nbsp; This conference includes quite a few &lt;a href="http://www.sqlteach.com/Session.aspx"&gt;interesting SQL Server-related 
sessions&lt;/a&gt;, on topics ranging from best practices, to performance, to some of 
the new SQL Server 2008 features. I fully expect this to be a great show.&lt;/p&gt;
&lt;p&gt;I am doing two breakout sessions during the main conference:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;SQL Server 2005: Authorization, Privilege, and Access Control&lt;/span&gt;.&amp;nbsp; In this 
talk I cover SQL Server 2005’s enhancements around granting permissions via 
stored modules (i.e., stored procedures, views, functions) 
&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight:bold;"&gt;Designing Highly Concurrent Database Applications&lt;/span&gt;.&amp;nbsp; In this talk I get 
into the business requirements behind supporting concurrent processes, and the 
areas where SQL Server (and every other database product) falls short. I then go 
on to show how to solve the problems in the database programmatically. 
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;I am also doing a &lt;strong&gt;full-day post-conference session on SQLCLR 
programming&lt;/strong&gt;. This will be the first time that I will be presenting all 
of my SQLCLR material in a single day; should be fun. I will take attendees from 
the basics all the way through some advanced applications and techniques, so if 
you’re interested in becoming a SQLCLR expert I highly recommend attending.&lt;/p&gt;
&lt;p&gt;The conference starts in just three weeks, but &lt;a href="http://www.sqlteach.com/Register.aspx"&gt;it is not too late to register&lt;/a&gt;.&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=[OT] SQLTeach: Almost Here&amp;amp;body=Seen on SQLblog.com: %0A%0A%09[OT] SQLTeach: Almost Here%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2008/04/24/ot-sqlteach-almost-here.aspx" target="_blank" title = "Email [OT] SQLTeach: Almost Here"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/24/ot-sqlteach-almost-here.aspx&amp;amp;title=%5bOT%5d+SQLTeach%3a+Almost+Here" target="_blank" title = "Submit [OT] SQLTeach: Almost Here to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/24/ot-sqlteach-almost-here.aspx&amp;amp;phase=2" target="_blank" title = "Submit [OT] SQLTeach: Almost Here to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/24/ot-sqlteach-almost-here.aspx&amp;amp;title=%5bOT%5d+SQLTeach%3a+Almost+Here" target="_blank" title = "Submit [OT] SQLTeach: Almost Here to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/24/ot-sqlteach-almost-here.aspx&amp;amp;title=%5bOT%5d+SQLTeach%3a+Almost+Here" target="_blank" title = "Submit [OT] SQLTeach: Almost Here to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/24/ot-sqlteach-almost-here.aspx&amp;amp;title=%5bOT%5d+SQLTeach%3a+Almost+Here&amp;amp;;top=1" target="_blank" title = "Add [OT] SQLTeach: Almost Here to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=6407" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="Conferences" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/Conferences/default.aspx" /><category term="SQLCLR" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/SQLCLR/default.aspx" /><category term="canada" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/canada/default.aspx" /><category term="devteach" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/devteach/default.aspx" /><category term="sqlteach" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/sqlteach/default.aspx" /></entry><entry><title>SQL Server Query Processing Puzzle: LIKE vs ?</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2008/04/22/sql-server-query-processing-puzzle-like-vs.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2008/04/22/sql-server-query-processing-puzzle-like-vs.aspx</id><published>2008-04-22T14:18:00Z</published><updated>2008-04-22T14:18:00Z</updated><content type="html">&lt;p&gt;How creative are you with manipulating your queries to produce more efficient plans? Try the following puzzle and e-mail your solution to me at [&amp;lt;my last name&amp;gt; @ pythian.com].  Make sure to include an explanation of why it works, as well as your mailing address. The best two solutions/explanations win a free copy of &lt;a href="http://www.amazon.com/dp/159059729X"&gt;Expert SQL Server 2005 Development&lt;/a&gt;, a wonderful feeling of accomplishment, plus eternal fame and glory when I reveal your solutions here on the blog.

&lt;/p&gt;&lt;p&gt;Run the following T-SQL to create two tables in TempDB:
&lt;/p&gt;&lt;pre style="margin-left:40px;"&gt;USE TempDB&lt;br&gt;GO&lt;br&gt;&lt;br&gt;CREATE TABLE b1 (blat1 CHAR(5) NOT NULL)&lt;br&gt;CREATE TABLE b2 (blat2 VARCHAR(200) NOT NULL)&lt;br&gt;GO&lt;br&gt;&lt;br&gt;INSERT b1&lt;br&gt;SELECT LEFT(AddressLine1, 5) AS blat1&lt;br&gt;FROM AdventureWorks.Person.Address&lt;br&gt;&lt;br&gt;INSERT b2&lt;br&gt;SELECT AddressLine1 AS blat2&lt;br&gt;FROM AdventureWorks.Person.Address&lt;br&gt;GO&lt;/pre&gt;
Now consider the following query:
&lt;pre style="margin-left:40px;"&gt;SELECT *&lt;br&gt;FROM b1&lt;br&gt;JOIN b2 ON&lt;br&gt;    b2.blat2 LIKE b1.blat1 + '%'&lt;/pre&gt;&lt;p&gt;
This query takes around three minutes to run on my notebook, and does over 1.8 million logical reads.  Can you figure out a way to re-write it so that it performs better?  No modification of the base tables or addition of any other objects is allowed (sorry, no indexed views!) -- the challenge is to tune this by doing nothing more than re-writing the query.

&lt;/p&gt;&lt;p&gt;Good luck!  I'll leave the contest open for submissions until May 1.&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=SQL Server Query Processing Puzzle: LIKE vs ?&amp;amp;body=Seen on SQLblog.com: %0A%0A%09SQL Server Query Processing Puzzle: LIKE vs ?%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2008/04/22/sql-server-query-processing-puzzle-like-vs.aspx" target="_blank" title = "Email SQL Server Query Processing Puzzle: LIKE vs ?"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/22/sql-server-query-processing-puzzle-like-vs.aspx&amp;amp;title=SQL+Server+Query+Processing+Puzzle%3a+LIKE+vs+%3f" target="_blank" title = "Submit SQL Server Query Processing Puzzle: LIKE vs ? to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/22/sql-server-query-processing-puzzle-like-vs.aspx&amp;amp;phase=2" target="_blank" title = "Submit SQL Server Query Processing Puzzle: LIKE vs ? to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/22/sql-server-query-processing-puzzle-like-vs.aspx&amp;amp;title=SQL+Server+Query+Processing+Puzzle%3a+LIKE+vs+%3f" target="_blank" title = "Submit SQL Server Query Processing Puzzle: LIKE vs ? to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/22/sql-server-query-processing-puzzle-like-vs.aspx&amp;amp;title=SQL+Server+Query+Processing+Puzzle%3a+LIKE+vs+%3f" target="_blank" title = "Submit SQL Server Query Processing Puzzle: LIKE vs ? to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/22/sql-server-query-processing-puzzle-like-vs.aspx&amp;amp;title=SQL+Server+Query+Processing+Puzzle%3a+LIKE+vs+%3f&amp;amp;;top=1" target="_blank" title = "Add SQL Server Query Processing Puzzle: LIKE vs ? to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=6344" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="Performance" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/Performance/default.aspx" /><category term="Query Tuning" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/Query+Tuning/default.aspx" /><category term="puzzle" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/puzzle/default.aspx" /></entry><entry><title>SQL Server Procedure Cache: More Relief on the Way</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2008/04/15/sql-server-procedure-cache-more-relief-on-the-way.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2008/04/15/sql-server-procedure-cache-more-relief-on-the-way.aspx</id><published>2008-04-16T00:26:00Z</published><updated>2008-04-16T00:26:00Z</updated><content type="html">&lt;p&gt;If you've read many of my blog posts, you know 
that I consider lack of procedure cache control to be a &lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2007/08/14/want-to-control-the-procedure-cache.aspx" class=""&gt;major SQL Server pain point&lt;/a&gt;. Badly written apps 
that use non-parameterized ad hoc queries can quickly flood SQL Server's memory 
pools and bring the server to its knees. &lt;/p&gt;
&lt;p&gt;SQL Server 2005 brought some relief in the form of 
the Forced Parameterization database option, and SP2 took things one step 
further with better throttling of the cache... but it's still not&amp;nbsp;enough.&amp;nbsp;We 
want a knob!&lt;/p&gt;
&lt;p&gt;The bad news: We're not getting quite the knob I 
was hoping for.&lt;/p&gt;
&lt;p&gt;The good news: SQL Server 2008 will include an 
&lt;strong&gt;sp_configure&lt;/strong&gt; option called&amp;nbsp;"&lt;strong&gt;optimize for ad hoc workloads&lt;/strong&gt;".&amp;nbsp; This option 
will cause the procedure cache to only cache the parameterized stubs for ad hoc 
queries, rather than the full query with parameters.&amp;nbsp; This means that 
applications passing a large number of non-parameterized batches should see much 
lower procedure cache memory utilization and, therefore, better overall 
throughput.&amp;nbsp; I'm really looking forward to seeing this in action;&amp;nbsp;this feature 
should be added with&amp;nbsp;the next&amp;nbsp;pre-release drop.&lt;/p&gt;
&lt;p&gt;Remember, there is simply no substitute for 
properly designing your application's data access layer, but hopefully this will 
help for those applications that simply can't be changed...&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=SQL Server Procedure Cache: More Relief on the Way&amp;amp;body=Seen on SQLblog.com: %0A%0A%09SQL Server Procedure Cache: More Relief on the Way%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2008/04/15/sql-server-procedure-cache-more-relief-on-the-way.aspx" target="_blank" title = "Email SQL Server Procedure Cache: More Relief on the Way"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/15/sql-server-procedure-cache-more-relief-on-the-way.aspx&amp;amp;title=SQL+Server+Procedure+Cache%3a+More+Relief+on+the+Way" target="_blank" title = "Submit SQL Server Procedure Cache: More Relief on the Way to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/15/sql-server-procedure-cache-more-relief-on-the-way.aspx&amp;amp;phase=2" target="_blank" title = "Submit SQL Server Procedure Cache: More Relief on the Way to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/15/sql-server-procedure-cache-more-relief-on-the-way.aspx&amp;amp;title=SQL+Server+Procedure+Cache%3a+More+Relief+on+the+Way" target="_blank" title = "Submit SQL Server Procedure Cache: More Relief on the Way to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/15/sql-server-procedure-cache-more-relief-on-the-way.aspx&amp;amp;title=SQL+Server+Procedure+Cache%3a+More+Relief+on+the+Way" target="_blank" title = "Submit SQL Server Procedure Cache: More Relief on the Way to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2008/04/15/sql-server-procedure-cache-more-relief-on-the-way.aspx&amp;amp;title=SQL+Server+Procedure+Cache%3a+More+Relief+on+the+Way&amp;amp;;top=1" target="_blank" title = "Add SQL Server Procedure Cache: More Relief on the Way to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=6234" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="Performance" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/Performance/default.aspx" /><category term="memory" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/memory/default.aspx" /><category term="procedure cache" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/procedure+cache/default.aspx" /></entry><entry><title>[personal] Career Changes</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2008/03/21/personal-career-changes.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2008/03/21/personal-career-changes.aspx</id><published>2008-03-21T13:53:00Z</published><updated>2008-03-21T13:53:00Z</updated><content type="html">&lt;p&gt;I generally shy away from writing personal blog posts about my life, but when it comes to major career changes it's kind of fun to share the news.&lt;/p&gt;&lt;p&gt;After almost three years as an independent consultant, I have stepped out of that business and into a full-time role with a company called &lt;a href="http://www.pythian.com/"&gt;The Pythian Group&lt;/a&gt;, a provider of remote DBA services.&amp;nbsp; Never heard of The Pythian Group?&amp;nbsp; That's because although the company is big in the &lt;a href="http://orana.info/technorati-ranking/"&gt;Oracle &lt;/a&gt;and &lt;a href="http://beerpla.net/2008/03/18/must-know-people-in-the-mysql-field/"&gt;MySQL &lt;/a&gt;worlds, it has just begun to make its move into the SQL Server arena.&amp;nbsp; My job title is Global Practice Lead for the SQL Server practice, and I am tasked with, among other things, increasing the company's presence and business on this side of the fence.&amp;nbsp; Fun stuff!&lt;/p&gt;&lt;p&gt;The Pythian Group has a very interesting business model that is at once both similar to what I knew as a consultant and totally foreign to the way I'm used to doing things. For example, as a consultant I generally billed my time in 15-minute increments; at The Pythian Group, time is billed in 1-minute increments -- great for the customer, not so great for the DBA. Luckily, they've built some tools to help ease the pain and after a week of totally hating the system I'm already starting to get used to it.&amp;nbsp; (Sort of).&amp;nbsp; &lt;/p&gt;&lt;p&gt;The company is heavily focused on automated monitoring and 24x7 support delivered via a network of offices around the globe -- things that as an independent consultant I never would have been able to deliver.&amp;nbsp; I'm really excited to watch things scale up from what is currently a relatively small SQL Server group to what I expect will eventually become a fairly large one.&amp;nbsp; I'm especially interested in seeing how some of the SQL Server 2008 tools -- such as Policy-Based Management -- will affect the way we work at Pythian.&amp;nbsp; As a consultant I was not especially enthusiastic about that feature.&amp;nbsp; As a remote DBA, it suddenly makes perfect sense.&lt;br&gt;&lt;/p&gt;&lt;p&gt;Anyway, thanks if you've read this far, and I'll end with a bit of a plug: if this stuff sounds at all interesting to you as a DBA, drop me a line.&amp;nbsp; We're hiring.&amp;nbsp; And don't let the 1-minute increment thing scare you (too much).&lt;br&gt; &lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=[personal] Career Changes&amp;amp;body=Seen on SQLblog.com: %0A%0A%09[personal] Career Changes%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2008/03/21/personal-career-changes.aspx" target="_blank" title = "Email [personal] Career Changes"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/03/21/personal-career-changes.aspx&amp;amp;title=%5bpersonal%5d+Career+Changes" target="_blank" title = "Submit [personal] Career Changes to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/03/21/personal-career-changes.aspx&amp;amp;phase=2" target="_blank" title = "Submit [personal] Career Changes to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/03/21/personal-career-changes.aspx&amp;amp;title=%5bpersonal%5d+Career+Changes" target="_blank" title = "Submit [personal] Career Changes to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/03/21/personal-career-changes.aspx&amp;amp;title=%5bpersonal%5d+Career+Changes" target="_blank" title = "Submit [personal] Career Changes to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2008/03/21/personal-career-changes.aspx&amp;amp;title=%5bpersonal%5d+Career+Changes&amp;amp;;top=1" target="_blank" title = "Add [personal] Career Changes to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5708" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="Personal" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/Personal/default.aspx" /><category term="career" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/career/default.aspx" /></entry><entry><title>SQL Server 2008: Return of the Debugger</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2008/02/29/sql-server-2008-return-of-the-debugger.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2008/02/29/sql-server-2008-return-of-the-debugger.aspx</id><published>2008-02-29T12:06:00Z</published><updated>2008-02-29T12:06:00Z</updated><content type="html">&lt;P&gt;A lot of people will be interested to know that at the launch event in LA it was &lt;A class="" href="http://blogs.msdn.com/dtjones/archive/2008/02/28/sql-server-2008-launch-the-day-after.aspx"&gt;announced that the T-SQL debugger is returning to Management Studio in SQL Server 2008&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;Personally, this is not a feature I've been lamenting the loss of; I never used it in SQL Server 2000, and unless we can view temp tables, table variables, etc, I just don't see it as something with a lot of utility for the way I personally develop T-SQL.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;But this isn't just about me, and I know that there was a huge amount of interested in seeing the debugger come back into the core SQL Server tools.&amp;nbsp; So congrats to all of the step debug fans out there; get your F10 keys ready for SQL Server 2008!&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=SQL Server 2008: Return of the Debugger&amp;amp;body=Seen on SQLblog.com: %0A%0A%09SQL Server 2008: Return of the Debugger%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2008/02/29/sql-server-2008-return-of-the-debugger.aspx" target="_blank" title = "Email SQL Server 2008: Return of the Debugger"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/02/29/sql-server-2008-return-of-the-debugger.aspx&amp;amp;title=SQL+Server+2008%3a+Return+of+the+Debugger" target="_blank" title = "Submit SQL Server 2008: Return of the Debugger to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/02/29/sql-server-2008-return-of-the-debugger.aspx&amp;amp;phase=2" target="_blank" title = "Submit SQL Server 2008: Return of the Debugger to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/02/29/sql-server-2008-return-of-the-debugger.aspx&amp;amp;title=SQL+Server+2008%3a+Return+of+the+Debugger" target="_blank" title = "Submit SQL Server 2008: Return of the Debugger to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/02/29/sql-server-2008-return-of-the-debugger.aspx&amp;amp;title=SQL+Server+2008%3a+Return+of+the+Debugger" target="_blank" title = "Submit SQL Server 2008: Return of the Debugger to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2008/02/29/sql-server-2008-return-of-the-debugger.aspx&amp;amp;title=SQL+Server+2008%3a+Return+of+the+Debugger&amp;amp;;top=1" target="_blank" title = "Add SQL Server 2008: Return of the Debugger to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5351" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="sql server 2008" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/sql+server+2008/default.aspx" /><category term="debugging" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/debugging/default.aspx" /></entry><entry><title>Who's On First? Solving the Top per Group Problem (Part 1: Technique)</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2008/02/08/who-s-on-first-solving-the-top-per-group-problem-part-1-technique.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2008/02/08/who-s-on-first-solving-the-top-per-group-problem-part-1-technique.aspx</id><published>2008-02-08T23:09:00Z</published><updated>2008-02-08T23:09:00Z</updated><content type="html">&lt;p&gt;Relative comparison is a simple matter of human nature. From early childhood we compare and contrast what we see in the world around us, building a means by which to rate what we experience. And as it turns out, this desire to discover top and bottom, rightmost and leftmost, or best and worst happens to extend quite naturally into business scenarios. Which product is the top seller? How about the one that's simply not moving off the shelves? Which of our customers has placed the most expensive order? What are the most recent orders placed at each of our outlets?&lt;/p&gt;&lt;p&gt;In the world of common business questions, the edge cases are generally of most interest. What's in the middle is unimportant; it's often too difficult for the mind to compare and comprehend when there are hundreds, thousands, or even millions of items, transactions, or facts that are all within a similar range. Instead, we focus on those that stick out in some extraordinary way.&lt;/p&gt;&lt;p&gt;Those of us who work with SQL products on a regular basis are faced with solving this same problem time and again as we work through various business requirements. Over time, I have noticed four basic query patterns that can be used to solve the problem; each are logically equivalent (within certain restrictions -- more on that later), but can have surprisingly different performance characteristics depending on the data being queried. In this first post, I will outline the available patterns/methods. In the following posts, I will show the results of testing each pattern against a variety of scenarios in an attempt to discover where and when each should be used.&lt;/p&gt;&lt;p&gt;The four basic patterns are outlined below. Each of the methods is illustrated using a query to show all customers' names, plus their most recent order date, and the amount of that order. I've included notes that indicate where logic differences can arise among the various methods.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Method 1: Join to full group and use correlated subquery with a MIN/MAX aggregate to filter&lt;/b&gt;&lt;/p&gt;&lt;p&gt;In this method we use an inner join to get all required columns, then filter the resultant set using a correlated subquery in the WHERE clause. &lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.FirstName,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.LastName,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.OrderDate,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.OrderAmount&lt;br&gt;FROM Customers c&lt;br&gt;JOIN Orders o ON o.CustomerId = c.CustomerId&lt;br&gt;WHERE &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.OrderDate&amp;nbsp; =&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT MAX(o1.OrderDate)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM Orders o1&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o1.CustomerId = o.CustomerId&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;br&gt;&lt;/blockquote&gt;&lt;p&gt;Logic notes: With this method ties are automatically included in the output, unless a tiebreaker is specified (which can be tricky given that you only have one column to work with). This method does not allow you to pull back an arbitrary number of rows, such as top 10 per customer; you are limited to the edge and any ties that might exist. &lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Method 1a: Join to full group and use correlated subquery with TOP(n) and ORDER BY to filter&lt;/b&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;This method is almost identical to Method 1 (which is why it is classified here as 1a), but the TOP and ORDER BY allow for a bit more flexibility than the aggregates.&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.FirstName,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.LastName,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.OrderDate,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.OrderAmount&lt;br&gt;FROM Customers c&lt;br&gt;JOIN Orders o ON o.CustomerId = c.CustomerId&lt;br&gt;WHERE &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.OrderDate&amp;nbsp; =&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT TOP(1)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o1.OrderDate&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM Orders o1&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o1.CustomerId = o.CustomerId&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ORDER BY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o1.OrderDate DESC&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/blockquote&gt;&lt;p&gt;Logic notes: With this method you can more easily integrate a tiebreaker than with Method 1; the comparison column can be anything, including a primary key, and you can still order on whatever column makes most sense. In addition, you can take more rows than with Method 1 by using IN instead of = in the WHERE clause, and increasing the argument value to TOP.&lt;br&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Method 2: CROSS APPLY to ordered TOP(n)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;In this method, SQL Server 2005's CROSS APPLY operator is used. This operator allows us to essentially create a table-valued correlated subquery -- something that impossible in previous versions of SQL Server. By using TOP in conjunction with ORDER BY we can get as many rows per group as needed.&lt;/p&gt;&lt;blockquote&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.FirstName,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.LastName,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.OrderDate,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.OrderAmount&lt;br&gt;FROM Customers c&lt;br&gt;CROSS APPLY&lt;br&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT TOP(1)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.OrderDate,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.OrderAmount&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM Orders o&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.CustomerId = c.CustomerId&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ORDER BY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.OrderDate DESC&lt;br&gt;) x&lt;br&gt;&lt;/blockquote&gt;&lt;p&gt;Logic notes: This method is almost identical, from a logic point of view, with Method 1a modified to use IN on a primary key column. With both methods WITH TIES can be added to the TOP in order to get ties.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Method 3: Join to derived table that uses a partitioned, ordered windowing function, and filter in the outer query based on the row number&lt;/b&gt;&lt;/p&gt;&lt;p&gt;In this method a derived table or CTE is used, in conjunction with a windowing function partitioned based on the required grain of the final query. So for the "most recent order per customer" query, the row number is partitioned based on the customer. This gives us a count starting at 1 for each customer, which can be filtered in the outer query.&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.FirstName,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.LastName,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.OrderDate,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.OrderAmount&lt;br&gt;FROM Customers c&lt;br&gt;INNER JOIN&lt;br&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.OrderDate,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.OrderAmount,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.CustomerId,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ROW_NUMBER() OVER&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PARTITION BY o.CustomerId&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ORDER BY o.OrderDate DESC&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) AS r&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM Orders o&lt;br&gt;) x ON&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.CustomerId = c.CustomerId&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; AND x.r = 1&lt;br&gt;&lt;/blockquote&gt;&lt;p&gt;Logic notes: If ties are important, use DENSE_RANK instead of ROW_NUMBER. ROW_NUMBER is good for arbitrary TOP(n), similar to Method 2. Unlike the previously described methods, in conjunction with DENSE_RANK this method can return an arbitrary TOP(n) rows, all of which can include ties. So if you would like to see the three most recent order dates and each happens to have multiple orders, this method will be able to return them all by simply filtering on x.r = 3. This would not be directly possible with any of the other methods described here.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Method 4: "Carry-along sort"&lt;/b&gt;&lt;/p&gt;&lt;p&gt;This is the only "tricky" method, and not one that I recommend using, except as a last resort. I'm including it here only for completeness and comparison because it happens to be a very high performance method in some cases. This method involves converting each of the required inner columns into a string, concatenating them, then applying an aggregate to the string as a whole. By putting the "sort" column first, the other data is "carried along" -- thus the name for the method. The concatenated data is then "unpacked" in the outer query. This can be surprisingly efficient from an I/O standpoint, but the resultant code is a maintenance nightmare and it is quite easy to introduce errors. In addition, this method can only return the top 1 per group -- no ties or multiple return items are supported.&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.FirstName,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c.LastName,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONVERT(DATETIME, SUBSTRING(x.OrderInfo, 1, 8)) AS OrderDate,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONVERT(MONEY, SUBSTRING(x.OrderInfo, 9, 15)) AS OrderAmount&lt;br&gt;FROM Customers c&lt;br&gt;INNER JOIN&lt;br&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.CustomerId,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MAX&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONVERT(CHAR(8), OrderDate, 112) +&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONVERT(CHAR(15), SubTotal)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) OrderInfo&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM Orders o&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GROUP BY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o.CustomerId&lt;br&gt;) x ON&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.CustomerId = c.CustomerId&lt;br&gt;&lt;/blockquote&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;This post is just the beginning; watch this space in the coming days for a series of performance tests and analysis of these methods, and some results that I personally found to be quite surprising.&lt;br&gt;&amp;nbsp;&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Who's On First? Solving the Top per Group Problem (Part 1: Technique)&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Who's On First? Solving the Top per Group Problem (Part 1: Technique)%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2008/02/08/who-s-on-first-solving-the-top-per-group-problem-part-1-technique.aspx" target="_blank" title = "Email Who's On First? Solving the Top per Group Problem (Part 1: Technique)"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/02/08/who-s-on-first-solving-the-top-per-group-problem-part-1-technique.aspx&amp;amp;title=Who%27s+On+First%3f+Solving+the+Top+per+Group+Problem+(Part+1%3a+Technique)" target="_blank" title = "Submit Who's On First? Solving the Top per Group Problem (Part 1: Technique) to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/02/08/who-s-on-first-solving-the-top-per-group-problem-part-1-technique.aspx&amp;amp;phase=2" target="_blank" title = "Submit Who's On First? Solving the Top per Group Problem (Part 1: Technique) to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/02/08/who-s-on-first-solving-the-top-per-group-problem-part-1-technique.aspx&amp;amp;title=Who%27s+On+First%3f+Solving+the+Top+per+Group+Problem+(Part+1%3a+Technique)" target="_blank" title = "Submit Who's On First? Solving the Top per Group Problem (Part 1: Technique) to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/02/08/who-s-on-first-solving-the-top-per-group-problem-part-1-technique.aspx&amp;amp;title=Who%27s+On+First%3f+Solving+the+Top+per+Group+Problem+(Part+1%3a+Technique)" target="_blank" title = "Submit Who's On First? Solving the Top per Group Problem (Part 1: Technique) to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2008/02/08/who-s-on-first-solving-the-top-per-group-problem-part-1-technique.aspx&amp;amp;title=Who%27s+On+First%3f+Solving+the+Top+per+Group+Problem+(Part+1%3a+Technique)&amp;amp;;top=1" target="_blank" title = "Add Who's On First? Solving the Top per Group Problem (Part 1: Technique) to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=4992" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="Performance" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/Performance/default.aspx" /><category term="Query Tuning" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/Query+Tuning/default.aspx" /><category term="T-SQL" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/T-SQL/default.aspx" /><category term="logic" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/logic/default.aspx" /></entry><entry><title>In case you don't read our Roller... Breaking news on RTM release date</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2008/01/25/in-case-you-don-t-read-our-roller-breaking-news-on-rtm-release-date.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2008/01/25/in-case-you-don-t-read-our-roller-breaking-news-on-rtm-release-date.aspx</id><published>2008-01-25T21:27:00Z</published><updated>2008-01-25T21:27:00Z</updated><content type="html">&lt;p&gt;And I quote...&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://blogs.technet.com/dataplatforminsider/archive/2008/01/25/microsoft-sql-server-2008-roadmap-clarification.aspx"&gt; final Release to manufacturing (RTM) of SQL Server 2008 expected in Q3.&lt;/a&gt; &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Thanks to &lt;a href="http://sqlblogcasts.com/blogs/jasonmassie/archive/2008/01/25/sql-server-2008-rtm-delayed-until-q3.aspx"&gt;Jason Massie&lt;/a&gt; for the pointer (via our &lt;a href="http://sqlblog.com/roller/roller.aspx"&gt;Roller&lt;/a&gt;, of course!)&amp;nbsp;&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=In case you don't read our Roller... Breaking news on RTM release date&amp;amp;body=Seen on SQLblog.com: %0A%0A%09In case you don't read our Roller... Breaking news on RTM release date%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2008/01/25/in-case-you-don-t-read-our-roller-breaking-news-on-rtm-release-date.aspx" target="_blank" title = "Email In case you don't read our Roller... Breaking news on RTM release date"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/01/25/in-case-you-don-t-read-our-roller-breaking-news-on-rtm-release-date.aspx&amp;amp;title=In+case+you+don%27t+read+our+Roller...+Breaking+news+on+RTM+release+date" target="_blank" title = "Submit In case you don't read our Roller... Breaking news on RTM release date to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/01/25/in-case-you-don-t-read-our-roller-breaking-news-on-rtm-release-date.aspx&amp;amp;phase=2" target="_blank" title = "Submit In case you don't read our Roller... Breaking news on RTM release date to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/01/25/in-case-you-don-t-read-our-roller-breaking-news-on-rtm-release-date.aspx&amp;amp;title=In+case+you+don%27t+read+our+Roller...+Breaking+news+on+RTM+release+date" target="_blank" title = "Submit In case you don't read our Roller... Breaking news on RTM release date to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/01/25/in-case-you-don-t-read-our-roller-breaking-news-on-rtm-release-date.aspx&amp;amp;title=In+case+you+don%27t+read+our+Roller...+Breaking+news+on+RTM+release+date" target="_blank" title = "Submit In case you don't read our Roller... Breaking news on RTM release date to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2008/01/25/in-case-you-don-t-read-our-roller-breaking-news-on-rtm-release-date.aspx&amp;amp;title=In+case+you+don%27t+read+our+Roller...+Breaking+news+on+RTM+release+date&amp;amp;;top=1" target="_blank" title = "Add In case you don't read our Roller... Breaking news on RTM release date to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=4691" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="sql server 2008" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/sql+server+2008/default.aspx" /></entry><entry><title>[New England] Special New England SQL Server Event with Itzik Ben-Gan</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2008/01/15/new-england-special-new-england-sql-server-event-with-itzik-ben-gan.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2008/01/15/new-england-special-new-england-sql-server-event-with-itzik-ben-gan.aspx</id><published>2008-01-15T17:55:00Z</published><updated>2008-01-15T17:55:00Z</updated><content type="html">&lt;P&gt;Just a&amp;nbsp;heads up for those in the Boston area: The &lt;A class="" href="http://www.nesql.org/"&gt;New England SQL Server Users Group&lt;/A&gt; is doing a special event next Wednesday night (January 23), featuring Itzik Ben-Gan, talking about Grouping Sets in SQL Server 2008:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;SQL Server 2008 introduces enhanced support for aggregating data addressing the needs to analyze aggregated data dynamically. The enhancements include the new GROUPING SETS clause, the standard CUBE and ROLLUP clauses (not to confuse those with the existing non-standard CUBE and ROLLUP options), the GROUPING_ID function, and other T-SQL enhancements. This session will cover those enhancements in detail, and will describe and demonstrate their practical uses.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This should be a great event, so mark your calendars and check the NESQL Web site for more information.&amp;nbsp;Please note that &lt;STRONG&gt;RSVP is&amp;nbsp;strongly encouraged&lt;/STRONG&gt;&amp;nbsp;for this event -- only people who RSVP will be eligible for giveaways that night, and we have a great selection. To get on the list to RSVP, please visit the &lt;A class="" href="http://www.nesql.org/"&gt;Web site&lt;/A&gt;&amp;nbsp;and sign up for our mailing list.&amp;nbsp; I will send a mailing -- which will&amp;nbsp;include RSVP instructions --&amp;nbsp;next Monday.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=[New England] Special New England SQL Server Event with Itzik Ben-Gan&amp;amp;body=Seen on SQLblog.com: %0A%0A%09[New England] Special New England SQL Server Event with Itzik Ben-Gan%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2008/01/15/new-england-special-new-england-sql-server-event-with-itzik-ben-gan.aspx" target="_blank" title = "Email [New England] Special New England SQL Server Event with Itzik Ben-Gan"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/01/15/new-england-special-new-england-sql-server-event-with-itzik-ben-gan.aspx&amp;amp;title=%5bNew+England%5d+Special+New+England+SQL+Server+Event+with+Itzik+Ben-Gan" target="_blank" title = "Submit [New England] Special New England SQL Server Event with Itzik Ben-Gan to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/01/15/new-england-special-new-england-sql-server-event-with-itzik-ben-gan.aspx&amp;amp;phase=2" target="_blank" title = "Submit [New England] Special New England SQL Server Event with Itzik Ben-Gan to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/01/15/new-england-special-new-england-sql-server-event-with-itzik-ben-gan.aspx&amp;amp;title=%5bNew+England%5d+Special+New+England+SQL+Server+Event+with+Itzik+Ben-Gan" target="_blank" title = "Submit [New England] Special New England SQL Server Event with Itzik Ben-Gan to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2008/01/15/new-england-special-new-england-sql-server-event-with-itzik-ben-gan.aspx&amp;amp;title=%5bNew+England%5d+Special+New+England+SQL+Server+Event+with+Itzik+Ben-Gan" target="_blank" title = "Submit [New England] Special New England SQL Server Event with Itzik Ben-Gan to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2008/01/15/new-england-special-new-england-sql-server-event-with-itzik-ben-gan.aspx&amp;amp;title=%5bNew+England%5d+Special+New+England+SQL+Server+Event+with+Itzik+Ben-Gan&amp;amp;;top=1" target="_blank" title = "Add [New England] Special New England SQL Server Event with Itzik Ben-Gan to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=4545" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="New England" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/New+England/default.aspx" /></entry><entry><title>A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx</id><published>2007-12-31T22:32:00Z</published><updated>2007-12-31T22:32:00Z</updated><content type="html">&lt;p&gt;As with all of the blog posts I keep &lt;i&gt;meaning&lt;/i&gt; to write -- I keep a list and given the infrequency with which I've been posting lately, it's getting quite large -- this script has been on the queue for quite some time. So here I find myself with a spare moment right on the cusp of the new year, and figured what better way to end the year than with a script that, at least for me, has been quite useful these last few months.&lt;/p&gt;&lt;p&gt;The driving force behind my writing this script is that I found myself endlessly calling &lt;b&gt;sp_who2 'active'&lt;/b&gt; to see who was doing what on servers I needed to take a look at. Then I would have to sort through the results, and end up calling &lt;b&gt;DBCC INPUTBUFFER&lt;/b&gt; to take a look at the SQL being used. This was a serious pain, and I finally caved a few months back and decided to end the madness once and for all with the help of some DMVs.&lt;/p&gt;&lt;p&gt;The following script primarily uses the &lt;b&gt;sys.dm_exec_requests&lt;/b&gt; view, and finds all "active" requests -- i.e., those that are running, about to start running, or suspended. It also finds some other useful information, including the host name, login name, the start time of the batch, and whether or not the batch is currently blocked. In the outer query I use the &lt;b&gt;sys.dm_exec_sql_text&lt;/b&gt; function to get the text of the SQL that all of the active requests are running, in addition to the SQL being run by the blocking sessions, if applicable. This way I don't have to do two lookups to chase down what's blocking what.&lt;/p&gt;&lt;p&gt;You'll notice that I use &lt;b&gt;FOR XML PATH&lt;/b&gt; in the subqueries that pull the SQL text. This gives us a nice little bonus: instead of copying the text out of the cell in SSMS and pasting it somewhere else, you can simply click on it -- and it maintains whatever formatting, including white space and carriage returns, that it originally had. This is much, much nicer than getting the batch on a single line. The only problem is that certain characters, such as greater-than and less-than, get "entitized" when the text is converted to XML. This means that some queries won't be able to be run without a bit of editing. A small price to pay for nicer output, in my opinion. If anyone out there has a solution for the entitization, please let me know! The only way I know to solve it is to convert back to VARCHAR, and that defeats the whole purpose...&lt;/p&gt;&lt;p&gt;Anyway, thanks all for a great 2007. Here's to an even better 2008! Without further ado, the script:&lt;/p&gt;&lt;blockquote&gt;&amp;nbsp;&lt;/blockquote&gt;&lt;blockquote&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.session_id,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.host_name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.login_name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.start_time,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.totalReads,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.totalWrites,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.totalCPU,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; x.writes_in_tempdb,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; text AS [text()]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM sys.dm_exec_sql_text(x.sql_handle)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FOR XML PATH(''), TYPE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) AS sql_text,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; COALESCE(x.blocking_session_id, 0) AS blocking_session_id,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p.text&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MIN(sql_handle) AS sql_handle&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM sys.dm_exec_requests r2&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r2.session_id = x.blocking_session_id&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) AS r_blocking&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CROSS APPLY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; text AS [text()]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM sys.dm_exec_sql_text(r_blocking.sql_handle)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FOR XML PATH(''), TYPE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) p (text)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) AS blocking_text&lt;br&gt;FROM&lt;br&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.session_id,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s.host_name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s.login_name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.start_time,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.sql_handle,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.blocking_session_id,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(r.reads) AS totalReads,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(r.writes) AS totalWrites,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(r.cpu_time) AS totalCPU,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SUM(tsu.user_objects_alloc_page_count + tsu.internal_objects_alloc_page_count) AS writes_in_tempdb&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM sys.dm_exec_requests r&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOIN sys.dm_exec_sessions s ON s.session_id = r.session_id&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOIN sys.dm_db_task_space_usage tsu ON s.session_id = tsu.session_id and r.request_id = tsu.request_id&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE r.status IN ('running', 'runnable', 'suspended')&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GROUP BY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.session_id,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s.host_name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s.login_name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.start_time,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.sql_handle,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.blocking_session_id&lt;br&gt;) x&lt;br&gt;&lt;/blockquote&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Enjoy!&lt;br&gt;&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?&amp;amp;body=Seen on SQLblog.com: %0A%0A%09A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx" target="_blank" title = "Email A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked?"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx&amp;amp;title=A+Gift+of+Script+for+2008%3a+Who%27s+Active%2c+What+Are+They+Doing%2c+and+Who+is+Blocked%3f" target="_blank" title = "Submit A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked? to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx&amp;amp;phase=2" target="_blank" title = "Submit A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked? to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx&amp;amp;title=A+Gift+of+Script+for+2008%3a+Who%27s+Active%2c+What+Are+They+Doing%2c+and+Who+is+Blocked%3f" target="_blank" title = "Submit A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked? to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx&amp;amp;title=A+Gift+of+Script+for+2008%3a+Who%27s+Active%2c+What+Are+They+Doing%2c+and+Who+is+Blocked%3f" target="_blank" title = "Submit A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked? to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/31/a-gift-of-script-for-2008-who-s-active-what-are-they-doing-and-who-is-blocked.aspx&amp;amp;title=A+Gift+of+Script+for+2008%3a+Who%27s+Active%2c+What+Are+They+Doing%2c+and+Who+is+Blocked%3f&amp;amp;;top=1" target="_blank" title = "Add A Gift of Script for 2008: Who's Active, What Are They Doing, and Who is Blocked? to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=4300" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="Scripts" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/Scripts/default.aspx" /><category term="DMVs" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/DMVs/default.aspx" /><category term="administration" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/administration/default.aspx" /></entry><entry><title>Anti-Patterns and Malpractices, Volume 1: Tumbling Data</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2007/12/15/anti-patterns-and-malpractices-volume-1-tumbling-data.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2007/12/15/anti-patterns-and-malpractices-volume-1-tumbling-data.aspx</id><published>2007-12-15T05:10:00Z</published><updated>2007-12-15T05:10:00Z</updated><content type="html">&lt;blockquote&gt;
&lt;p&gt;&lt;i&gt;"Lonely but free I'll be found&lt;br&gt;
Drifting along with the tumbling tumbleweeds"&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&amp;nbsp;- Supremes, "Tumbling Tumble Weeds"&lt;/i&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Welcome to the first installment of what I hope will be a regular feature on this blog, Anti-Patterns and Malpractices. As a consultant, I get the honor of seeing a lot of different systems, with a lot of different code. Some of it is good, and some of it -- well -- I'll be featuring that which is not so good here. No names will be named, and code will be changed to protect the not-so-innocent; my goal is not to call out or embarrass anyone, but rather to expose those misguided patterns and practices which inevitably lead to problems (and a subsequent call to a consultant; perhaps if I post enough of these I'll have fewer less-than-appealing encounters in my work!)&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The topic du jour is the Tumbling Data Anti-Pattern, a name coined by my friend Scott Diehl. Much like the tumbleweed lazily blowing around in the dust, data which exhibits this pattern is slowly and painstakingly moved from place to place, gaining little value along the way.&lt;/p&gt;
&lt;p&gt;So what exactly typifies this particular anti-pattern? Consider the following block of T-SQL, designed to count all married employees in the AdventureWorks HumanResources.Employee table and bucket them into age ranges of 20-35 and 36-50, grouped by gender. Employees older than 50 should be disregarded:&lt;/p&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;--Find all married employees&lt;br&gt;SELECT *&lt;br&gt;INTO #MarriedEmployees&lt;br&gt;FROM HumanResources.Employee&lt;br&gt;WHERE &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MaritalStatus = 'M'&lt;br&gt;&lt;br&gt;/*&lt;br&gt;select * from #marriedemployees where employeeid = 20&lt;br&gt;*/&lt;br&gt;&lt;br&gt;--Find employees between 20 and 35&lt;br&gt;SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EmployeeId&lt;br&gt;INTO #MarriedEmployees_20_35&lt;br&gt;FROM #MarriedEmployees&lt;br&gt;WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATEDIFF(year, birthdate, getdate()) BETWEEN 20 AND 35&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;--Find employees between 36 and 50&lt;br&gt;SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EmployeeId&lt;br&gt;INTO #MarriedEmployees_36_50&lt;br&gt;FROM #MarriedEmployees&lt;br&gt;WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATEDIFF(year, birthdate, getdate()) BETWEEN 36 AND 50&lt;br&gt;&lt;br&gt;&lt;br&gt;--Remove the employees older than 50&lt;br&gt;DELETE&lt;br&gt;FROM #MarriedEmployees&lt;br&gt;WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EmployeeId NOT IN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT EmployeeId&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM #MarriedEmployees_20_35&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; AND &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EmployeeId NOT IN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT EmployeeId&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM #MarriedEmployees_36_50&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;br&gt;&lt;br&gt;--Count the remaining employees&lt;br&gt;SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.Gender,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; COUNT(*) AS theCount&lt;br&gt;INTO #Employee_Gender_Count_20_35&lt;br&gt;FROM #MarriedEmployees e&lt;br&gt;JOIN #MarriedEmployees_20_35 m ON e.EmployeeId = m.EmployeeId&lt;br&gt;GROUP BY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.Gender&lt;br&gt;&lt;br&gt;--select * from #Employee_Gender_Count_20_35&lt;br&gt;&lt;br&gt;SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.Gender,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; COUNT(*) AS theCount&lt;br&gt;INTO #Employee_Gender_Count_36_50&lt;br&gt;FROM #MarriedEmployees e&lt;br&gt;JOIN #MarriedEmployees_36_50 m ON e.EmployeeId = m.EmployeeId&lt;br&gt;GROUP BY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.Gender&lt;br&gt;&lt;br&gt;--Get the final answer&lt;br&gt;SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.Gender,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.theCount AS [20 to 35],&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.theCount AS [36 to 50]&lt;br&gt;FROM #Employee_Gender_Count_20_35 a&lt;br&gt;JOIN #Employee_Gender_Count_36_50 b ON b.Gender = a.Gender&lt;br&gt;&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;This kind of code tells us several things about the person who wrote it. Rather than thinking upfront and designing a complete solution or at least a game plan before typing, this person appears to have thought through the problem at hand in a step-by-step manner, coding along the way. A bit of debugging was done along the way, but the real goal was to spit out an answer as quickly as possible (or so it seemed at the time). No attempt was made to go back and fix the extraneous code or do any cleanup; why bother, when we already have an answer?&lt;/p&gt;&lt;p&gt;It's important to mention that this is a simple example. I generally see this anti-pattern exploited when developers are tasked with producing large, complex reports against data sources that aren't quite as well-designed as they could be. In an attempt to preserve sanity, the developer codes each tiny data transformation in a separate statement, slowly morphing the data into the final form he wishes to output. The resultant scripts are often thousands of lines long and take hours to run, during which time the server crawls (and throughout the office you can hear people muttering "the server sure is slow today"). &lt;/p&gt;&lt;p&gt;The solution to this problem is simple, of course, and the best software engineers do it automatically: Before writing a line of code sit back for just a moment and consider your end goal. Do you need to work in steps, or will a single query suffice? Can various join conditions and predicates be merged? Perhaps a Google search is a good idea; what is the best way to produce a histogram without a temp table?&lt;/p&gt;&lt;p&gt;The hurried atmosphere of many companies leads to a "get it done right now--even if it's far from perfect" attitude that ends up wasting a lot more time than it saves. The above example code block took me around 10 minutes to put together. A single-query version took me under two minutes to code. It is less than a third of the length, runs approximately 500 times faster, and uses 0.4% of the resources. All because I spent a couple of moments reflecting on where I was going before I took the first step.&lt;/p&gt;&lt;p&gt;If you find yourself exploiting this anti-pattern, step back and question whether this code will have a life beyond the current query window. If it will ever be checked into source control, it's probably a good idea to go back and do some cleanup. &lt;/p&gt;&lt;p&gt;If you find yourself tasked with maintaining code that looks like what I've posted, my suggestion is to simply re-write it from scratch. I was recently faced with a script containing over 2000 lines of this kind of thing, and I spent almost two days slowly working my way through the mess trying to make sense of it. On the evening of the second day, after talking with some of the shareholders, I realized that it was actually a simple problem to solve. One hour later and I had a new, totally functional solution -- a couple of hundred lines long, and several orders of magnitude faster. Sometimes it's best not to wade through a muddy puddle, when you can simply hop right over.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Anti-Patterns and Malpractices, Volume 1: Tumbling Data&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Anti-Patterns and Malpractices, Volume 1: Tumbling Data%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2007/12/15/anti-patterns-and-malpractices-volume-1-tumbling-data.aspx" target="_blank" title = "Email Anti-Patterns and Malpractices, Volume 1: Tumbling Data"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/15/anti-patterns-and-malpractices-volume-1-tumbling-data.aspx&amp;amp;title=Anti-Patterns+and+Malpractices%2c+Volume+1%3a+Tumbling+Data" target="_blank" title = "Submit Anti-Patterns and Malpractices, Volume 1: Tumbling Data to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/15/anti-patterns-and-malpractices-volume-1-tumbling-data.aspx&amp;amp;phase=2" target="_blank" title = "Submit Anti-Patterns and Malpractices, Volume 1: Tumbling Data to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/15/anti-patterns-and-malpractices-volume-1-tumbling-data.aspx&amp;amp;title=Anti-Patterns+and+Malpractices%2c+Volume+1%3a+Tumbling+Data" target="_blank" title = "Submit Anti-Patterns and Malpractices, Volume 1: Tumbling Data to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/15/anti-patterns-and-malpractices-volume-1-tumbling-data.aspx&amp;amp;title=Anti-Patterns+and+Malpractices%2c+Volume+1%3a+Tumbling+Data" target="_blank" title = "Submit Anti-Patterns and Malpractices, Volume 1: Tumbling Data to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/15/anti-patterns-and-malpractices-volume-1-tumbling-data.aspx&amp;amp;title=Anti-Patterns+and+Malpractices%2c+Volume+1%3a+Tumbling+Data&amp;amp;;top=1" target="_blank" title = "Add Anti-Patterns and Malpractices, Volume 1: Tumbling Data to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=3982" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="Performance" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/Performance/default.aspx" /><category term="malpractices" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/malpractices/default.aspx" /><category term="software development" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/software+development/default.aspx" /><category term="anti-patterns" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/anti-patterns/default.aspx" /></entry><entry><title>SQL Server 2008 CTP5 VHD Now Available</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2007/12/05/sql-server-2008-ctp5-vhd-now-available.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2007/12/05/sql-server-2008-ctp5-vhd-now-available.aspx</id><published>2007-12-05T15:46:00Z</published><updated>2007-12-05T15:46:00Z</updated><content type="html">&lt;P&gt;Lazy developer that I am, I just hate running installers to set up VHDs for the SQL Server 2008 CTPs.&amp;nbsp; So I was overjoyed when Microsoft did the work for me and released a pre-installed VHD image for CTP4.&lt;/P&gt;
&lt;P&gt;CTP5, alas, did not ship with a VHD, forcing me once again down the path of the dreaded installer.&amp;nbsp;But today I'm happy to report that Microsoft has once again come through for those of us who simply can't be bothered to click the "Next" button; &lt;A class="" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=6A39AFFA-DB6E-48A9-82E4-4EFD6705F4A6&amp;amp;displaylang=en&amp;amp;mdc_uxref=sl"&gt;a VHD for CTP5 has appeared on the Microsoft Download Center&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;So download, enjoy, and think of all of the effort you'll save by not having to install...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=SQL Server 2008 CTP5 VHD Now Available&amp;amp;body=Seen on SQLblog.com: %0A%0A%09SQL Server 2008 CTP5 VHD Now Available%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2007/12/05/sql-server-2008-ctp5-vhd-now-available.aspx" target="_blank" title = "Email SQL Server 2008 CTP5 VHD Now Available"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/05/sql-server-2008-ctp5-vhd-now-available.aspx&amp;amp;title=SQL+Server+2008+CTP5+VHD+Now+Available" target="_blank" title = "Submit SQL Server 2008 CTP5 VHD Now Available to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/05/sql-server-2008-ctp5-vhd-now-available.aspx&amp;amp;phase=2" target="_blank" title = "Submit SQL Server 2008 CTP5 VHD Now Available to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/05/sql-server-2008-ctp5-vhd-now-available.aspx&amp;amp;title=SQL+Server+2008+CTP5+VHD+Now+Available" target="_blank" title = "Submit SQL Server 2008 CTP5 VHD Now Available to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/05/sql-server-2008-ctp5-vhd-now-available.aspx&amp;amp;title=SQL+Server+2008+CTP5+VHD+Now+Available" target="_blank" title = "Submit SQL Server 2008 CTP5 VHD Now Available to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2007/12/05/sql-server-2008-ctp5-vhd-now-available.aspx&amp;amp;title=SQL+Server+2008+CTP5+VHD+Now+Available&amp;amp;;top=1" target="_blank" title = "Add SQL Server 2008 CTP5 VHD Now Available to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=3703" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="sql server 2008" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/sql+server+2008/default.aspx" /><category term="installer" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/installer/default.aspx" /></entry><entry><title>"Cursors Run Just Fine"</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2007/10/13/cursors-run-just-fine.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2007/10/13/cursors-run-just-fine.aspx</id><published>2007-10-13T13:42:00Z</published><updated>2007-10-13T13:42:00Z</updated><content type="html">&lt;p&gt;I found Linchi's recent post on &lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2007/10/09/t-sql-cursors-the-case-of-the-published-tpc-e-tests.aspx"&gt;use of cursors in the TPC-E test&lt;/a&gt; to be quite interesting. The question is, why are cursors used in the test when the commonly accepted notion within the SQL Server community is that cursors are a bad thing?&lt;/p&gt;&lt;p&gt;I've posted in the past about situations where cursors were actually &lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/running-sums-redux.aspx"&gt;faster than set-based queries&lt;/a&gt;. But in this case I just don't see it; cursoring over an input set to do an update? There's no way that's going to be faster.&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.sqlserver.org.au/blogs/greg_linwood/default.aspx"&gt;Greg Linwood&lt;/a&gt; commented in Linchi's post that "indexed cursors run just fine for most purposes". And although I have loads of respect for Greg and his opinions, I just can't agree in this case.&amp;nbsp; I did a few tests on my end just to make sure, and indexed or not, even for the simplest of of queries, cursors perform at least a few times more slowly than their set-based equivalents.&amp;nbsp; Greg mentioned in this comment that the SQL Server engine executes even set-based queries "internally using cursor style processing", but a loop in the query processor's code is clearly not the same as a T-SQL cursor. &lt;/p&gt;&lt;p&gt;The query processor is optimized internally to process data without having to pass it around to different spots in memory or switch context, whereas with a cursor the data is transferred into local variables and your code has to constantly ask the query processor to go back and get some more. This is extremely expensive, which is why even in my experiments with situations where you can see superior performance with cursors, I found that a SQLCLR cursor--which doesn't have to do nearly as much work as a T-SQL cursor--is &lt;a href="http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/running-sums-yet-again-sqlclr-saves-the-day.aspx"&gt;vastly superior&lt;/a&gt;.&lt;br&gt;&lt;/p&gt;&lt;p&gt;I'll close with a simple example.&amp;nbsp; The following two batches each run in AdventureWorks, and indexes are irrelevant in both cases.&amp;nbsp; See for yourself which is faster.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;--Set-based&lt;br&gt;SELECT SUM(Quantity)&lt;br&gt;FROM Production.TransactionHistory&lt;br&gt;GO&lt;br&gt;&lt;br&gt;&lt;br&gt;--Cursor-based&lt;br&gt;DECLARE @q INT&lt;br&gt;INT @t INT&lt;br&gt;SET @t = 0&lt;br&gt;&lt;br&gt;DECLARE c CURSOR &lt;br&gt;LOCAL FAST_FORWARD&lt;br&gt;FOR&lt;br&gt;SELECT Quantity &lt;br&gt;FROM Production.Transactionhistory&lt;br&gt;&lt;br&gt;OPEN c&lt;br&gt;&lt;br&gt;FETCH NEXT FROM c INTO @q&lt;br&gt;&lt;br&gt;WHILE @@FETCH_STATUS = 0&lt;br&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET @t = @t + @q&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FETCH NEXT FROM c INTO @q&lt;br&gt;END&lt;br&gt;&lt;br&gt;CLOSE c&lt;br&gt;DEALLOCATE c&lt;br&gt;&lt;br&gt;SELECT @t&lt;br&gt;GO &lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=&amp;quot;Cursors Run Just Fine&amp;quot;&amp;amp;body=Seen on SQLblog.com: %0A%0A%09&amp;quot;Cursors Run Just Fine&amp;quot;%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2007/10/13/cursors-run-just-fine.aspx" target="_blank" title = "Email &amp;quot;Cursors Run Just Fine&amp;quot;"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/10/13/cursors-run-just-fine.aspx&amp;amp;title=%26quot%3bCursors+Run+Just+Fine%26quot%3b" target="_blank" title = "Submit &amp;quot;Cursors Run Just Fine&amp;quot; to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/10/13/cursors-run-just-fine.aspx&amp;amp;phase=2" target="_blank" title = "Submit &amp;quot;Cursors Run Just Fine&amp;quot; to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/10/13/cursors-run-just-fine.aspx&amp;amp;title=%26quot%3bCursors+Run+Just+Fine%26quot%3b" target="_blank" title = "Submit &amp;quot;Cursors Run Just Fine&amp;quot; to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/10/13/cursors-run-just-fine.aspx&amp;amp;title=%26quot%3bCursors+Run+Just+Fine%26quot%3b" target="_blank" title = "Submit &amp;quot;Cursors Run Just Fine&amp;quot; to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2007/10/13/cursors-run-just-fine.aspx&amp;amp;title=%26quot%3bCursors+Run+Just+Fine%26quot%3b&amp;amp;;top=1" target="_blank" title = "Add &amp;quot;Cursors Run Just Fine&amp;quot; to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=2949" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="Performance" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/Performance/default.aspx" /><category term="cursors" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/cursors/default.aspx" /></entry><entry><title>Code Camps and Revisiting a Common Theme</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2007/09/29/code-camps-and-revisiting-a-common-theme.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2007/09/29/code-camps-and-revisiting-a-common-theme.aspx</id><published>2007-09-29T19:33:00Z</published><updated>2007-09-29T19:33:00Z</updated><content type="html">&lt;P&gt;Today I gave two talks at &lt;A class="" href="http://www.thedevcommunity.org/Events/PresentationList.aspx?id=4"&gt;New England Code Camp 8&lt;/A&gt;. A fun experience as always, and for those of you who were in my talks and are looking for decks/code, please see &lt;A class="" href="http://sqlblog.com/blogs/adam_machanic/archive/2007/05/11/thank-you-for-attending-today-s-webcast-on-authorization-privilege-and-access-control.aspx"&gt;this post&lt;/A&gt; and &lt;A class="" href="http://sqlblog.com/blogs/adam_machanic/archive/2007/05/18/another-webcast-thanks-errors-and-exceptions-in-sql-server-2005.aspx"&gt;this post&lt;/A&gt; from when I did slightly different versions of the same talks earlier this year as MSDN Webcsts. I am not quite ready to publish the decks I used today.&lt;/P&gt;
&lt;P&gt;But the topic of this post is not so much the code camp as an observation about what I saw there.&amp;nbsp;Recent posts by both of our resident Andys (&lt;A class="" href="http://sqlblog.com/blogs/andrew_kelly/archive/2007/09/27/double-standard.aspx"&gt;Kelly&lt;/A&gt; and &lt;A class="" href="http://sqlblog.com/blogs/andy_leonard/archive/2007/07/12/database-professionals-an-enterprise-requirement.aspx"&gt;Leonard&lt;/A&gt;) share the theme of organizations treating their database staff&amp;nbsp;as&amp;nbsp;next-to-worthless.&amp;nbsp;&amp;nbsp;And developers, in general, seem much more interested in other facets of&amp;nbsp;development than&amp;nbsp;all of that "database stuff." &lt;/P&gt;
&lt;P&gt;Today's code camp proved this once again; my two talks were both quite lightly attended, even though I was talking about&amp;nbsp;important issues around data security and exception handling--things that any developer working with data should get. Perhaps it's just me, but the evidence says otherwise: after my talks I peeked into a few others and found a standing room only session on Silverlight and a session on LINQ to SQL&amp;nbsp;that had a comparable number of attendees to what I'd had.&lt;/P&gt;
&lt;P&gt;Why is it that data, while&amp;nbsp;the foundation of any business&amp;nbsp;application,&amp;nbsp;is&amp;nbsp;not a draw to&amp;nbsp;the developer masses?&amp;nbsp;How can we&amp;nbsp;ignore the data and instead focus on creating spiffy new UIs (to display flawed data, no doubt)?&amp;nbsp;Perhaps data seems easy--if you know how to write a query and set up an ADO.NET connection, that's all you need, right?&amp;nbsp; Or perhaps data is just someone else's job--just let the DBA or database developer handle it and display anything that comes back, flawed or not. It's not your problem, you're a UI developer. But everyone can't be a UI developer, can they?&amp;nbsp; Someone has to take control of the data.&lt;/P&gt;
&lt;P&gt;Bad data can and does lead to project failure. If you're a UI developer you're going to get canned just as quickly as the DBA if you're project is no longer being funded--so if your UI displays bad data,&amp;nbsp;you are&amp;nbsp;&lt;EM&gt;just as guilty as&amp;nbsp;whomever designed the&amp;nbsp;database that returned it&lt;/EM&gt;! If you're a business&amp;nbsp;tier developer, you are just as responsible for data validation as the database developer!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alas, if you're reading this post you're already one of the converted.&amp;nbsp;This is SQLblog.com, so you obviously care enough about your data to read up on it a bit more.&amp;nbsp;But as developers who know the value and importance of data, it is our job to spread the data gospel.&amp;nbsp;Data issues around security, validation, and performance are every developer's&amp;nbsp;responsibility.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Code Camps and Revisiting a Common Theme&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Code Camps and Revisiting a Common Theme%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2007/09/29/code-camps-and-revisiting-a-common-theme.aspx" target="_blank" title = "Email Code Camps and Revisiting a Common Theme"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/09/29/code-camps-and-revisiting-a-common-theme.aspx&amp;amp;title=Code+Camps+and+Revisiting+a+Common+Theme" target="_blank" title = "Submit Code Camps and Revisiting a Common Theme to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/09/29/code-camps-and-revisiting-a-common-theme.aspx&amp;amp;phase=2" target="_blank" title = "Submit Code Camps and Revisiting a Common Theme to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/09/29/code-camps-and-revisiting-a-common-theme.aspx&amp;amp;title=Code+Camps+and+Revisiting+a+Common+Theme" target="_blank" title = "Submit Code Camps and Revisiting a Common Theme to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/09/29/code-camps-and-revisiting-a-common-theme.aspx&amp;amp;title=Code+Camps+and+Revisiting+a+Common+Theme" target="_blank" title = "Submit Code Camps and Revisiting a Common Theme to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2007/09/29/code-camps-and-revisiting-a-common-theme.aspx&amp;amp;title=Code+Camps+and+Revisiting+a+Common+Theme&amp;amp;;top=1" target="_blank" title = "Add Code Camps and Revisiting a Common Theme to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=2744" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author><category term="Security" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/Security/default.aspx" /><category term="code samples" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/code+samples/default.aspx" /><category term="developers" scheme="http://sqlblog.com/blogs/adam_machanic/archive/tags/developers/default.aspx" /></entry><entry><title>Want to Control the Procedure Cache?</title><link rel="alternate" type="text/html" href="http://sqlblog.com/blogs/adam_machanic/archive/2007/08/14/want-to-control-the-procedure-cache.aspx" /><id>http://sqlblog.com/blogs/adam_machanic/archive/2007/08/14/want-to-control-the-procedure-cache.aspx</id><published>2007-08-14T12:29:00Z</published><updated>2007-08-14T12:29:00Z</updated><content type="html">&lt;p&gt;... I know I do.&amp;nbsp; How many times have you seen the procedure cache bloat, for no good reason, because of badly designed applications? How many times have you been frustrated by the fact that SQL Server handles this in a relatively boneheaded way, and just keeps growing it and growing it--an especially huge problem on 64-bit systems?&lt;/p&gt;&lt;p&gt;So far I've not had great luck with Connect, but I figured I'd try again.&amp;nbsp; This is something we need &lt;i&gt;now&lt;/i&gt;.&amp;nbsp; So if you are concerned about this issue, please vote...&lt;/p&gt;&lt;div&gt;&lt;a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=293188"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=293188&lt;/a&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Want to Control the Procedure Cache?&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Want to Control the Procedure Cache?%0A%0Ahttp://sqlblog.com/blogs/adam_machanic/archive/2007/08/14/want-to-control-the-procedure-cache.aspx" target="_blank" title = "Email Want to Control the Procedure Cache?"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/08/14/want-to-control-the-procedure-cache.aspx&amp;amp;title=Want+to+Control+the+Procedure+Cache%3f" target="_blank" title = "Submit Want to Control the Procedure Cache? to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/08/14/want-to-control-the-procedure-cache.aspx&amp;amp;phase=2" target="_blank" title = "Submit Want to Control the Procedure Cache? to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/08/14/want-to-control-the-procedure-cache.aspx&amp;amp;title=Want+to+Control+the+Procedure+Cache%3f" target="_blank" title = "Submit Want to Control the Procedure Cache? to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/adam_machanic/archive/2007/08/14/want-to-control-the-procedure-cache.aspx&amp;amp;title=Want+to+Control+the+Procedure+Cache%3f" target="_blank" title = "Submit Want to Control the Procedure Cache? to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/adam_machanic/archive/2007/08/14/want-to-control-the-procedure-cache.aspx&amp;amp;title=Want+to+Control+the+Procedure+Cache%3f&amp;amp;;top=1" target="_blank" title = "Add Want to Control the Procedure Cache? to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=2203" width="1" height="1"&gt;</content><author><name>Adam Machanic</name><uri>http://sqlblog.com/members/Adam+Machanic.aspx</uri></author></entry></feed>