<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 't-sql' and 'Best Practices'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=t-sql,Best+Practices&amp;orTags=0</link><description>Search results matching tags 't-sql' and 'Best Practices'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Bad habits to kick : ORDER BY ordinal</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/06/bad-habits-to-kick-order-by-ordinal.aspx</link><pubDate>Tue, 06 Oct 2009 14:49:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:17313</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;&lt;i&gt;A few weeks ago, I wrote a post about forming a new habit: &lt;a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2009/09/03/ladies-and-gentlemen-start-your-semi-colons.aspx" title="http://sqlblog.com/blogs/aaron_bertrand/archive/2009/09/03/ladies-and-gentlemen-start-your-semi-colons.aspx" target="_blank"&gt;always terminate statements with semi-colons&lt;/a&gt;.&amp;nbsp; Today I thought I would start a series on kicking bad habits that many of us have developed over time.&amp;nbsp; I provided a little more background on this series &lt;a href="http://bit.ly/1dZv6G" title="http://www.onetooneinteractive.com/otolabs-posts/2009/10/10/helping-people-kick-bad-sql-server-habits/" target="_blank"&gt;over on my company's site&lt;/a&gt;.&amp;nbsp; Today's topic: using ordinal numbers in our ORDER BY clauses.&amp;nbsp; &lt;/i&gt;&lt;/p&gt;&lt;p&gt;At least once a week, I catch myself using ordinal position to define order.&amp;nbsp; For example, I might have this:&amp;nbsp; &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table cellpadding="0" cellspacing="0" bgcolor="#eeeeee"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;foo&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;bar&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;  FROM&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.splunge&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;  ORDER&amp;nbsp;BY&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;2&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;DESC&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is lazy shorthand, and is bound to get screwed up at some point unless I have encrypted the stored procedure and threw away the key.&amp;nbsp; Invariably, someone at some point is going to come in and add a column, remove a column, or change the order of the columns.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Remember that a lot of us produce stored procedures to be consumed by essentially "dumb" clients - Windows forms or web applications that lack the ability to perform any ordering on their own.&amp;nbsp; So often the ORDER BY clause of a resultset coming back from a stored procedure is pretty important.&amp;nbsp; When editing a stored procedure that has an error-prone ORDER BY clause like the above, it is very easy to make changes to the SELECT list without even looking at the ORDER BY clause, or the reverse.&amp;nbsp; Imagine the web developer using the above procedure asks to change the SELECT list.&amp;nbsp; Now he wants mort, foo, bar.&amp;nbsp; (Note that order of the columns themselves should be irrelevant to the application, since it should be using column name and not ordinal references, but in some cases we like certain columns to appear in a certain order when we are debugging in SSMS and the like.)&amp;nbsp; So assume you do exactly as the developer asks, and edit the SELECT clause and alter the procedure:&lt;/p&gt;


&lt;blockquote&gt;
&lt;table cellpadding="0" cellspacing="0" bgcolor="#eeeeee"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&lt;/font&gt;mort, &lt;font color="black"&gt;foo&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;bar&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;  FROM&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.splunge&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;  ORDER&amp;nbsp;BY&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;2&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;DESC&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Oops!&amp;nbsp; Now the developer is complaining that his UI is broken because the order is all messed up.&amp;nbsp; This would not have happened if you had used the following syntax in the first place:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table cellpadding="0" cellspacing="0" bgcolor="#eeeeee"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&lt;/font&gt;mort, &lt;font color="black"&gt;foo&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;bar&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;  FROM&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.splunge&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;  ORDER&amp;nbsp;BY&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;foo&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;bar&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;DESC&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;I know it is hard to spell out those column names when you're doing ad
hoc stuff, but getting in the habit will potentially save your bacon
someday.&amp;nbsp; And you can't use the excuse that you have very complicated expressions in your SELECT list, because ORDER BY is the only place in the entire query where you can reference an alias you provided.&amp;nbsp; So the following is completely legal:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table cellpadding="0" cellspacing="0" bgcolor="#eeeeee"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;foo&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;RTRIM&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="magenta"&gt;CONVERT&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;ABS&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;foo&lt;/font&gt;&lt;font color="gray"&gt;) % 2))&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.splunge&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;ORDER&amp;nbsp;BY &lt;/font&gt;&lt;font color="black"&gt;foo&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;There is nothing lost by being explicit, except for a few keystrokes.&amp;nbsp; But there is plenty to lose by not doing so - including some patience for the developer running to your cube like their head is on fire.&amp;nbsp; Ideally, when you are making changes to existing code, you examine the entire statement to ensure consistency.&amp;nbsp; But try to be proactive and protect yourself against the inevitable rushed and possibly botched emergency fix.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;i&gt;I am working on a series of "Bad habits to kick" articles, in an effort to motivate people to drop some of the things that I hate to see when I inherit code.&amp;nbsp; Up next: &lt;a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/07/bad-habits-to-kick-using-a-loop-to-populate-a-table.aspx" title="http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/07/bad-habits-to-kick-using-a-loop-to-populate-a-table.aspx" target="_blank"&gt;using loops to populate large tables&lt;/a&gt;. &lt;/i&gt;&lt;br&gt;&lt;/p&gt;</description></item><item><title>disallow results from triggers</title><link>http://sqlblog.com/blogs/louis_davidson/archive/2009/06/06/disallow-results-from-triggers.aspx</link><pubDate>Sun, 07 Jun 2009 02:38:06 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14514</guid><dc:creator>drsql</dc:creator><description>&lt;p&gt;A setting that I noticed a while back when looking at sys.configurations was &lt;strong&gt;disallow results from triggers.&lt;/strong&gt;&amp;#160; Triggers are one of my favorite subjects, and you will find a lot of good uses of them in my book (triggers are also well named, as poor usage of them will allow you to shoot your foot off in a heartbeat as I discussed in my earlier post: &lt;a title="http://sqlblog.com/blogs/louis_davidson/archive/2008/07/13/triggers-evil.aspx" href="http://sqlblog.com/blogs/louis_davidson/archive/2008/07/13/triggers-evil.aspx"&gt;http://sqlblog.com/blogs/louis_davidson/archive/2008/07/13/triggers-evil.aspx&lt;/a&gt;). &lt;/p&gt;  &lt;p&gt;One of the main ways you can mess up your system is to have triggers that return results, often by accident, that the client doesn’t know about.&amp;#160; There are three kinds of return values that are interesting:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Result sets &lt;/li&gt;    &lt;li&gt;Raiserror messages &lt;/li&gt;    &lt;li&gt;Rowcount messages &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Also note that this is an overall system configuration. So it will disallow results from triggers in all of your databases.&amp;#160; It is never a good idea to return data from a trigger, but it is actually pretty useful for testing.&amp;#160; In the following code, I will test this setting and show how it will affect returning data to the client from the aforementioned methods.&amp;#160; &lt;/p&gt;  &lt;p&gt;What will the setting do? It will raise an error if you try to do a result set.&amp;#160; It will automatically suppress rowcount messages (without the need for SET NOCOUNT ON), but will allow error messages (I won’t cover it here, but error messages can cause issues with transactions in triggers, particularly when coupled with TRY…CATCH blocks).&lt;/p&gt;  &lt;p&gt;To demonstrate the setting, I will use tempdb.&amp;#160; Checking the system setting for your server, use:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;SELECT value      &lt;br /&gt;FROM&amp;#160;&amp;#160;&amp;#160; sys.configurations       &lt;br /&gt;WHERE name = 'disallow results from triggers'&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;This will probably return, unless you have discovered the setting before I did, in which case you probably aren’t reading any longer, so there.&lt;/p&gt;  &lt;p&gt;---------    &lt;br /&gt;0 &lt;/p&gt;  &lt;p&gt;To show you the effect of this setting , let's build the following scenario. The trigger will return 3 types of values&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;the contents of the table named triggerResult &lt;/li&gt;    &lt;li&gt;the rowcount of rows affected from an insert statement like you would normally have in a database &lt;/li&gt;    &lt;li&gt;the rowcount of the rows from the insert statement into a temp table &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;To start, we create 2 tables, one as the “main” table, and another that will hold the results of a side effect causing query:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;--primary test table      &lt;br /&gt;create table triggerResult       &lt;br /&gt;(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; triggerResultId int primary key       &lt;br /&gt;)&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;--holds our side effect to prove the trigger executed       &lt;br /&gt;create table triggerResultSideEffect       &lt;br /&gt;(       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; triggerResultId int       &lt;br /&gt;)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Then we will create the trigger that gives us several different types of output    &lt;br /&gt;    &lt;br /&gt;&lt;font size="2" face="Courier New"&gt;create trigger triggerResult$insertTrigger      &lt;br /&gt;on triggerResult       &lt;br /&gt;after insert       &lt;br /&gt;as       &lt;br /&gt;begin       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; --returns a result set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; select triggerResultId       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; from&amp;#160;&amp;#160; triggerResult&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; --side effect like you might expect in a trigger      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; insert into triggerResultSideEffect (triggerResultId)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; select triggerResultId       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; from&amp;#160;&amp;#160; inserted&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; --just to get a fixed rowcount output      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; declare @test table (value char(1))       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; insert into @test       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; values (1)       &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; --and a couple of errors      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; raiserror ('Low',10,1)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; raiserror ('Normal',16,1) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;end      &lt;br /&gt;&lt;/font&gt;Now we will test out the trigger by inserting one row into the triggerResult table:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;insert into triggerResult      &lt;br /&gt;values (1)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This returns (the final rows affected is from the original statement): &lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;triggerResultId      &lt;br /&gt;---------------       &lt;br /&gt;1 &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;(1 row(s) affected) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;(1 row(s) affected) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;(1 row(s) affected) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;Low      &lt;br /&gt;Msg 50000, Level 16, State 1, Procedure triggerResult$insertTrigger, Line 22       &lt;br /&gt;Normal &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;(1 row(s) affected) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Now try a multi-row operation, to see the difference &lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;insert into triggerResult      &lt;br /&gt;values (2),(3),(4)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This returns the following (which you can clearly now see the different number of rows that were affected by each statement, 4 from the one that returns all of the rows in the table, 3 from the side effect query that inserts the rows from the inserted table.&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;triggerResultId      &lt;br /&gt;---------------       &lt;br /&gt;1       &lt;br /&gt;2       &lt;br /&gt;3       &lt;br /&gt;4 &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;(4 row(s) affected) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;(3 row(s) affected) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;(1 row(s) affected) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;Low      &lt;br /&gt;Msg 50000, Level 16, State 1, Procedure triggerResult$insertTrigger, Line 22       &lt;br /&gt;Normal &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;(3 row(s) affected)&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;Now, change the setting to disallow trigger results (you may need to do allow advanced options) &lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;exec sp_configure 'show advanced options',1      &lt;br /&gt;RECONFIGURE       &lt;br /&gt;exec sp_configure 'disallow results from triggers',1       &lt;br /&gt;RECONFIGURE&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Now, just to make sure of where our data is, we know that there are 4 rows in the triggerResult table. Let’s check the triggerResultSideEffect table contents:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;SELECT *      &lt;br /&gt;FROM&amp;#160;&amp;#160; triggerResultSideEffect       &lt;br /&gt;ORDER&amp;#160; BY triggerResultId &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This returns, showing all of the values we have inserted: &lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;triggerResultId      &lt;br /&gt;---------------       &lt;br /&gt;1       &lt;br /&gt;2       &lt;br /&gt;3       &lt;br /&gt;4&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;Now, trying to run the statement with the same trigger:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;insert into triggerResult      &lt;br /&gt;values (5)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This will cause the following error message: &lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" size="2" face="Courier New"&gt;Msg 524, Level 16, State 1, Procedure triggerResult$insertTrigger, Line 6      &lt;br /&gt;A trigger returned a resultset and the server option 'disallow results from triggers' is true.&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;Altering the trigger, just remove the statement that returns a result set:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;alter trigger triggerResult$insertTrigger      &lt;br /&gt;on triggerResult       &lt;br /&gt;after insert       &lt;br /&gt;as       &lt;br /&gt;begin       &lt;br /&gt;&lt;strong&gt;&lt;em&gt;&amp;#160;&amp;#160;&amp;#160; ----returns a result set          &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; --select triggerResultId           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; --from&amp;#160;&amp;#160; triggerResult           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; --side effect like you might expect in a trigger&lt;/em&gt;&lt;/strong&gt;&amp;#160;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; insert into triggerResultSideEffect (triggerResultId)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; select triggerResultId       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; from&amp;#160;&amp;#160; inserted &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; --just to get a fixed rowcount output      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; declare @test table (value char(1))       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; insert into @test       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; values (1) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; --and a couple of errors      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; raiserror ('Low',10,1)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; raiserror ('Normal',16,1) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;end &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Now, re-executing the statement with no results being returned: &lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;insert into triggerResult      &lt;br /&gt;values (5) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This simply returns the error message that are returned, and the rows affected message from the insert statement: &lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;Low      &lt;br /&gt;Msg 50000, Level 16, State 1, Procedure triggerResult$insertTrigger, Line 22       &lt;br /&gt;Normal &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;(1 row(s) affected)&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;Just to make sure that the rows were created:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;select *      &lt;br /&gt;from&amp;#160;&amp;#160; triggerResult &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;select *      &lt;br /&gt;from&amp;#160;&amp;#160; triggerResultSideEffect&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;This returns: &lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;triggerResultId      &lt;br /&gt;---------------       &lt;br /&gt;1       &lt;br /&gt;2       &lt;br /&gt;3       &lt;br /&gt;4       &lt;br /&gt;5 &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;(5 row(s) affected) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;triggerResultId      &lt;br /&gt;---------------       &lt;br /&gt;1       &lt;br /&gt;4       &lt;br /&gt;3       &lt;br /&gt;2       &lt;br /&gt;5 &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;(5 row(s) affected)&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;Which shows that the data was inserted..&lt;/p&gt;  &lt;p&gt;Note that books online states: This feature will be removed in the next version of Microsoft SQL Server. Do not use this feature in new development work, and modify applications that currently use this feature as soon as possible. We recommend that you set this value to 1. &lt;/p&gt;  &lt;p&gt;This means that the ability to return result sets from a trigger will go away in the next version of SQL Server.&amp;#160; Returning results from a trigger is certainly not something that has ever been a good practice, so if this does in fact occur, it is a good setting to set in your development servers and begin to use.&lt;/p&gt;</description></item><item><title>My stored procedure &amp;quot;best practices&amp;quot; checklist</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2008/10/30/my-stored-procedure-best-practices-checklist.aspx</link><pubDate>Thu, 30 Oct 2008 21:40:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:9728</guid><dc:creator>AaronBertrand</dc:creator><description>When developing stored procedures, there seems to be a lot of emphasis on "get it done fast."  Which means type all lower case, pay little attention to formatting, and sometimes throw best practices out the window.  
Personally, I would rather front-load my development time; I think that the costs I pay in initial development far outweigh what I might have paid in maintenance down the road.  Making readable and maintainable code that also 
performs well and is delivered in a timely manner is something that a lot of us strive for, but we don't always have the luxury.  But I have found that it is very easy to fall into the good kind of development habits. 

&lt;p&gt;A popular adage is, "you can have it fast, cheap, or good.  Pick two."  I contend that if you develop habits like these and use them in all of your database programming, the time difference between following those methods and 
doing it the "lazy" way will be negligible at most; and so, fast and good go hand in hand, rather than trade off for one another.
&lt;/p&gt;

&lt;p&gt;Once in a while this "disorder" slows me down.  I come across code that someone else wrote (almost exclusively it is someone I no longer work with), and I can't even bear to look at it without first re-writing it.  Here is a fake 
but realistic example of the kinds of procedures I see:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;create&amp;nbsp;proc&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;foo&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="#434343"&gt;@i&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;int&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="#434343"&gt;@bar&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;int=&lt;/font&gt;&lt;font color="gray"&gt;null,&lt;/font&gt;&lt;font color="#434343"&gt;@hr&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;int output&lt;/font&gt;&lt;font color="black"&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="#434343"&gt;@xd&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;datetime&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;as&lt;br&gt;declare&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@c&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;varchar&lt;br&gt;declare&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@s&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;nchar&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;2&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;declare&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@x&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;int&lt;br&gt;set&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@grok&lt;/font&gt;&lt;font color="blue"&gt;=&lt;/font&gt;&lt;font color="red"&gt;'Beverly'&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;set&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@korg&lt;/font&gt;&lt;font color="blue"&gt;=&lt;/font&gt;&lt;font color="red"&gt;'MA'&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;set&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@x&lt;/font&gt;&lt;font color="blue"&gt;=&lt;/font&gt;&lt;font color="black"&gt;5&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;select&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;customers.customerid&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;firstname&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;lastname&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="black"&gt;orderdate&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;from&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;customers&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;join&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;orders&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;on&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;customers.customerid&lt;/font&gt;&lt;font color="blue"&gt;=&lt;/font&gt;&lt;font color="black"&gt;orders.customerid&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;where&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;status&lt;/font&gt;&lt;font color="blue"&gt;=&lt;/font&gt;&lt;font color="#434343"&gt;@i&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;or&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;status&lt;/font&gt;&lt;font color="gray"&gt;&amp;lt;=&lt;/font&gt;&lt;font color="#434343"&gt;@bar&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;and&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;orderdate&lt;/font&gt;&lt;font color="gray"&gt;&amp;lt;=&lt;/font&gt;&lt;font color="#434343"&gt;@xd&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;set&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@hr&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;@@rowcount &lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;select&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;customers.customerid&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="magenta"&gt;count&lt;/font&gt;&lt;font color="gray"&gt;(*)&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;from&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;customers&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;left&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;join&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;orders&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;on&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;customers.customerid&lt;/font&gt;&lt;font color="blue"&gt;=&lt;/font&gt;&lt;font color="black"&gt;orders.customerid&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;where&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;customers.city&lt;/font&gt;&lt;font color="blue"&gt;=&lt;/font&gt;&lt;font color="#434343"&gt;@c&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;and&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;customers.state&lt;/font&gt;&lt;font color="blue"&gt;=&lt;/font&gt;&lt;font color="#434343"&gt;@s&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;&lt;br&gt;group&amp;nbsp;by&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;customers.customerid&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;having&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;count&lt;/font&gt;&lt;font color="gray"&gt;(*)&amp;gt;=&lt;/font&gt;&lt;font color="#434343"&gt;@x&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;return&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="magenta"&gt;@@rowcount&lt;/font&gt;&lt;font color="gray"&gt;)&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;This kind of feels like the 5th grade all over again, but when I get handed code like this, I start immediately visualizing one of those "find all of the things wrong with this picture" exercises, and feel compelled to fix them all.  
So, what is wrong with the above sample, you may ask?  Well, let me go through my own personal (and quite subjective) subconscious checklist of best practices when I write my own stored procedures.  I have never tried to 
list these all at once, so I may be all over the place, but hopefully I will justify why I choose to have these items on my checklist in the first place.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Upper casing T-SQL keywords and built-in functions&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I always use CREATE PROCEDURE and not create procedure or Create Procedure.  Same goes for all of the code throughout my objects... you will always see SELECT, FROM, WHERE and not select, from, where.  I just find if 
much more readable when all of the keywords are capitalized. It's not that hard for me to hold down the shift key while typing these words, and there are even IDEs that will do this kind of replacement for you (for example, &lt;a href="http://www.apexsql.com/sql_tools_edit.asp" title="http://www.apexsql.com/sql_tools_edit.asp" target="_blank"&gt;Apex 
SQLEdit&lt;/a&gt; has a handy "mis-spelled keyword replacement" feature that I think could be used for this purpose also).   This is probably one of the few areas where Celko and I 
actually agree.  :-)
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using a proper and consistent naming scheme&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;Obviously "foo" is a horribly ridiculous name for a procedure, but I have come across many that were equally nondescript.  I like to name my objects using {target}_{verb}.  So for example, if I have a Customers table, I would 
have procedures such as:
&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dbo.Customer_Create
&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dbo.Customer_Update
&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dbo.Customer_Delete
&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dbo.Customer_GetList
&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dbo.Customer_GetDetails
&lt;/p&gt;

&lt;p&gt;This allows them to sort nicely in Object Explorer / Object Explorer Details, and also narrows down my search quickly in an IntelliSense (or &lt;a href="http://www.red-gate.com/products/SQL_Prompt/index.htm" title="http://www.red-gate.com/products/SQL_Prompt/index.htm" target="_blank"&gt;SQLPrompt&lt;/a&gt;) auto-
complete list.  If I have a stored procedures named in the style dbo.GetCustomerList, they get mixed up in the list with dbo.GetClientList and dbo.GetCreditList.  You could argue that maybe these should be organized by 
schema, but in spite of all the buzz, I have not developed a need or desire to use schemas in this way.  For most of the applications I develop, ownership/schema is pretty simple and doesn't need to be made more complex.
&lt;/p&gt;

&lt;p&gt;Of course I NEVER name stored procedures using the sp_ prefix.  See Brian Moran's &lt;a href="http://www.sqlmag.com/Article/ArticleID/23011/sql_server_23011.html" title="Should I Use the sp_ Prefix for Procedure Names?" target="_blank"&gt;article in SQL Server Magazine&lt;/a&gt; back in 2001.  Or just ask 
anybody.  :-)  I also avoid other identifying object prefixes (like usp_).  I don't know that I've ever been in a situation where I couldn't tell that some object was a procedure, or a function, or a table, and where the name really 
would have helped me all that much.  This is especially true for the silly (but common) "tbl" prefix on tables.  I don't want to get into that here, but I've always scratched my head at that one.  Views may be the only place 
where I think this is justified, but then it should be a v or View_ prefix on the views only; no need to also identify tables... if it doesn't have a v or View_ prefix, it's a table!
&lt;/p&gt;

&lt;p&gt;More important than coming up with a proper naming scheme (because that is mostly subjective), it is much more important that you apply your naming scheme consistently.  Nobody wants to see procedures named 
dbo.Customer_Create, dbo.Update_Customer and dbo.GetCustomerDetails.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using the schema prefix&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I always specify the schema prefix when creating stored procedures.  This way I know that it will be dbo.procedure_name no matter who I am logged in as when I create it.  Similarly, my code always has the schema prefix on 
all object references.  This prevents the database engine from checking for an object under my schema first, and also avoids the issue where multiple plans are cached for the exact same statement/batch just because they were executed by users with different default schemas.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using parentheses around parameter list&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I am not a big fan of using parentheses around the parameter list.  I can't really explain it, as I am a proponent of consistency, and this is the syntax required when creating user-defined functions.  But I wanted to mention it 
because you will not see any of my stored procedures using this syntax.  I'm open to change if you can suggest a good enough reason for me to do so.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Lining up parameter names, data types, and default values&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I find this much easier to read:
&lt;/p&gt;


&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;PROCEDURE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.User_Update&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;@CustomerID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;@FirstName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;32&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL,&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;@LastName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;32&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL,&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;@Password&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;16&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL,&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;@EmailAddress&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;320&lt;/font&gt;&lt;font color="gray"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL,&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;@Active&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;BIT&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;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;@LastLogin&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SMALLDATETIME&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;BEGIN&lt;/font&gt;&lt;br&gt;...&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;...than this:
&lt;/p&gt;


&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;PROCEDURE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.User_Update&lt;br&gt;&lt;/font&gt;&lt;font color="#434343"&gt;@CustomerID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&lt;/font&gt;&lt;font color="#434343"&gt;@FirstName&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;32&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL,&lt;br&gt;&lt;/font&gt;&lt;font color="#434343"&gt;@LastName&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;32&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL,&lt;br&gt;&lt;/font&gt;&lt;font color="#434343"&gt;@Password&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;16&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL,&lt;br&gt;&lt;/font&gt;&lt;font color="#434343"&gt;@EmailAddress&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;320&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL,&lt;br&gt;&lt;/font&gt;&lt;font color="#434343"&gt;@Active&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;BIT&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&lt;/font&gt;&lt;font color="#434343"&gt;@LastLogin&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SMALLDATETIME&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;BEGIN&lt;br&gt;&lt;/font&gt;...&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using spaces and line breaks liberally&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;This is a simple one, but in all comparison operators I like to see spaces between column/variable and operator.  So instead of @foo int=null or where @foo&amp;gt;1 I would rather see @foo INT = NULL or WHERE @foo &amp;gt; 1.
&lt;/p&gt;

&lt;p&gt;I also tend to place at least a carriage return between individual statements, especially in stored procedures where many statements spill over multiple lines.
&lt;/p&gt;

&lt;p&gt;Both of these are just about readability, nothing more.  While in some interpreted languages like JavaScript, size is king, and compressing / obfuscating code to make it as small as possible does provide some benefit, in T-
SQL you would be hard-pressed to find a case where this comes into play.  So, I lean to the side of readability.
&lt;/p&gt;

&lt;p&gt;======================&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Avoiding data type / function prefixes on column / parameter names&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I often see prefixes like @iCustomerID, @prmInputParameter, @varLocalVariable, @strStringVariable.  I realize why people do it, I just think it muddies things up.  It also makes it much harder to change the data type of a 
column when not only do you have to change all the variable/parameter declarations but you also have to change @iVarName to @bigintVarName, etc.  Otherwise the purpose of the prefixed variable name loses most of its 
benefit.  So, just name the variable for what it is.  If you have a column EmailAddress VARCHAR(320), then make your variable/parameter declaration @EmailAddress VARCHAR(320).  No need to use @strEmailAddress ... if 
you need to find out the data type, just go to the declaration line!
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using lengths on parameters, even when optional&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I occasionally see people define parameters and local variables as char or varchar, without specifying a length.  This is very dangerous, as in many situations you will get silent truncation at 30 characters, and in a few obscure 
ones, you will get silent truncation at 1 character.  This can mean data loss, which is not very good at all.  I have asked that this silent truncation at least become consistent throughout the product (see &lt;a href="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=267605" title="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=267605" target="_blank"&gt;Connect #267605&lt;/a&gt;), but nothing has happened yet.  Fellow MVP Erland Sommarskog has gone so far as to ask for the length declaration to become 
mandatory (see &lt;a href="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=244395" title="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=244395" target="_blank"&gt;Connect #244395&lt;/a&gt;) and, failing that, feels that this should be something that raises a warning when using his 
proposed SET STRICT_CHECKS ON setting (see &lt;a href="http://www.sommarskog.se/strict_checks.html#nodefaultlength" title="http://www.sommarskog.se/strict_checks.html#nodefaultlength" target="_blank"&gt;http://www.sommarskog.se/strict_checks.html#nodefaultlength&lt;/a&gt;).
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Listing output parameters last&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;My habit is to list OUTPUT parameters last.  I am not sure why that is exactly, except that it is the order that I conceptually think about the parameters... in then out, not the other way around.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using BEGIN / END liberally&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I have seen many people write stuff like this:
&lt;/p&gt;


&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;PROCEDURE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.ProcedureA&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;*&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;foo&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;*&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;bar&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;They create the procedure, maybe don't notice the extra resultset from bar (or shrug it off), and then wonder why they only get results from foo when they run the procedure.  If they had done this:
&lt;/p&gt;


&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;PROCEDURE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.ProcedureA&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;*&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;foo&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;*&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;bar&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;END&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Because GO is not a T-SQL keyword but rather a batch separator for tools like Query Analyzer and SSMS, they would have received these error messages, one from each batch: &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;Msg 102, Level 15, State 1, Procedure ProcedureA, Line 4&lt;br&gt;Incorrect syntax near ';'.&lt;br&gt;Msg 102, Level 15, State 1, Line 2&lt;br&gt;Incorrect syntax near 'END'.&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yes, errors are bad, and all that, but I would rather have this brought to my face when I try to compile the procedure, then later on when the first user tries to call it.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using statement terminators&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I have quickly adapted to the habit of ending all statements with proper statement terminators (;).  This was always a habit in languages like JavaScript (where it is optional) and C# (where it is not).  But as T-SQL gets more 
and more extensions (e.g. CTEs) that require it, I see it becoming a requirement eventually.  Maybe I won't even be working with SQL Server by the time that happens, but if I am, I'll be ready.  It's one extra keystroke and 
guarantees that my code will be forward-compatible.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using SET NOCOUNT ON&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I always add SET NOCOUNT ON; as the very first line of the procedure (after BEGIN of course).  This prevents DONE_IN_PROC messages from needlessly being sent back to the client after every row-affecting statement, which 
increases network traffic and in many cases can fool applications into believing there is an additional recordset available for consumption. &lt;br&gt;&lt;/p&gt;

&lt;ul&gt;&lt;span style="font-weight:bold;"&gt;NOTE&lt;/span&gt;&lt;br&gt;I do not advocate blindly throwing SET NOCOUNT ON into all of your existing stored procedures.  If you have existing applications they might actually already be working around the "extra recordset" problem, or there may be .NET applications that are using its result.  If you code with SET NOCOUNT ON from the start, and keep track of rows affected in output parameters when necessary, this should never be an issue.  Roy Ashbrook got beat up about this topic at a Tampa code camp last summer, and &lt;a href="http://drowningintechnicaldebt.com/blogs/royashbrook/archive/2007/07/17/why-quot-set-nocount-on-quot-sucks.aspx" target="_blank"&gt;wrote about it here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
&lt;/ul&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using local variables&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;When possible, I always use a single DECLARE statement to initialize all of my local variables.  Similarly, I try to use a single SELECT to apply values to those variables that are being used like local constants.  I see code like 
this:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;declare&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@foo&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;int&lt;br&gt;declare&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@bar&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;int&lt;br&gt;declare&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@x&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;int&lt;br&gt;set&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@foo&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;5&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;set&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@bar&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;6&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;set&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@x&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;-&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;And then some more declare and set statements later on in the code.  I find it much harder to track down variables in longer and more complex procedures when the declaration and/or assignments can happen anywhere... I 
would much rather have as much of this as possible occurring in the beginning of the code.  So for the above I would rather see: &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;DECLARE &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@foo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@bar&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@x&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@foo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;5&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@bar&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;6&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@x&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;-&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;As a bonus, in SQL Server 2008, the syntax now supports changing the above into a single statement:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;DECLARE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@foo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;5&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@bar&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;6&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@x&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;-&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;So much nicer.  However, it still leaves a lot to be desired: I also always use meaningful variables names, rather than @i, @x, etc.&lt;/p&gt;

&lt;p&gt;Also, some people like listing the commas at the beginning of each new line, e.g.: &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;DECLARE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@foo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;5&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="#434343"&gt;@bar&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;6&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;/font&gt;&lt;font color="#434343"&gt;@x&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;-&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Not just in variable declarations, but also in parameter lists, columns lists, etc.  While I will agree that this makes it easier to comment out individual lines in single steps, I find the readability suffers greatly.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using table aliases&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I use aliases a lot.  Nobody wants to read (never mind type) this, even though I have seen *many* examples of it posted to the public SQL Server newsgroups:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_X_with_long_name.column1&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_X_with_long_name.column2&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_X_with_long_name.column3&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_X_with_long_name.column4&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_X_with_long_name.column5&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_H_with_long_name.column1&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_H_with_long_name.column2&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_H_with_long_name.column3&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_H_with_long_name.column4&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_X_with_long_name&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;INNER&amp;nbsp;JOIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_H_with_long_name&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;ON&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_X_with_long_name.column1&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_H_with_long_name.column1&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;OR&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_X_with_long_name.column1&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_H_with_long_name.column1&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;OR&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_X_with_long_name.column1&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_H_with_long_name.column1&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_X_with_long_name.column1&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;&amp;gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;5&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;AND&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_X_with_long_name.column1&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;&amp;lt;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;10&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;But as long as you alias sensibly, you can make this a much more readable query: &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;X.column1&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;X.column2&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;X.column3&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;X.column4&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;X.column5&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;H.column1&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;H.column2&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;H.column3&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;H.column4&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_X_with_long_name&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;X&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;INNER&amp;nbsp;JOIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.table_H_with_long_name&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;H&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;ON&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;X.column1&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;H.column1&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;OR&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;X.column2&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;H.column2&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;OR&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;X.column3&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;H.column3&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;X.column1&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;&amp;gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;5&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;AND&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;X.column1&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;&amp;lt;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;10&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;The "AS" when aliasing tables is optional; I have been trying very hard to make myself use it (only because the standard defines it that way).  When writing multi-table queries, I don't give tables meaningless shorthand like a, 
b, c or t1, t2, t3.  This might fly for simple queries, but if the query becomes more complex, you will regret it when you have to go back and edit it.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using column aliases&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I buck against the trend here.  A lot of people prefer to alias expressions / columns using this syntax:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[column&amp;nbsp;expression]&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;alias&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;I much prefer: &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;alias&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[column&amp;nbsp;expression]&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;The reason is that all of my column names are listed down the left hand side of the column list, instead of being at the end.  It is much easier to scan column names when they are vertically aligned.
&lt;/p&gt;

&lt;p&gt;In addition, I always use column aliases for expressions, even if right now I don't need to reference the column by an alias.  This prevents me from having to deal with multiple errors should I ever need to move the query into a 
subquery, or cte, or derived table, etc.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using consistent formatting&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I am very fussy (some co-workers use a different word) about formatting.  I like my queries to be consistently readable and laid out in a predictable way.  So for a join that includes a CTE and a subquery, this is how it would 
look:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;WITH&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;cte&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS &lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;t.col1&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;t.col2&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;t.col3&lt;br&gt;&amp;nbsp;&amp;nbsp;  &lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;/font&gt;&lt;font color="black"&gt;dbo.sometable&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;t&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;cte.col1&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;cte.col2&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;cte.col3&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;c.col4&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt; cte&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;INNER&amp;nbsp;JOIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;dbo.Customers&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;c&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;ON&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;c.CustomerID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;cte.col1&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHERE&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;EXISTS&lt;br&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;1&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Orders o&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;WHERE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;o.CustomerID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;= &lt;font color="black"&gt;c&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt;.CustomerID&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;AND&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;c.Status&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'LIVE'&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Keeping all of the columns in a nice vertical line, and visually separating each table in the join and each where clause.  Inside a subquery or derived table, I am less strict about the visual separation, though I still put each fundamental portion 
on its own line.  And I always use SELECT 1 in this type of EXISTS() clause, instead of SELECT * or SELECT COUNT(*), to make it immediately clear to others that the query inside does NOT retrieve data.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Matching case of underlying objects / columns&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I always try to match the case of the underlying object, as I can never be too certain that my application will always be on a case-sensitive collation.  Going back and correcting the case throughout all of my modules will be a 
royal pain, at best.  This is much easier if you are using SQL Server 2008 Management Studio against a SQL Server 2008 instance, or have invested in Red-Gate's SQL Prompt, as you will automatically get the correct case when selecting from the auto-complete list.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Qualifying column names with table/alias prefix&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I always qualify column names when there is more than one table in the query.  Heck, sometimes I even use aliases when there is only one table in the query, to ease my maintenance later should the query become more 
complex.  I won't harp on this too much, as fellow MVP Alex Kuznetsov &lt;a href="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2008/10/25/defensive-database-programming-qualifying-column-names.aspx" title="http://sqlblog.com/blogs/alexander_kuznetsov/archive/2008/10/25/defensive-database-programming-qualifying-column-names.aspx" target="_blank"&gt;treated this subject&lt;/a&gt; a few days ago.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using RETURN and OUTPUT appropriately&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;I never use RETURN to provide any data back to the client (e.g. the SCOPE_IDENTITY() value or @@ROWCOUNT).  This should be used exclusively for returning stored procedure status, such as ERROR_NUMBER() / @@ERROR.  If you need to return data to the caller, use a resultset or an OUTPUT parameter.&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Avoiding keyword shorthands&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I always use full keywords as opposed to their shorthand equivalents.  "BEGIN TRAN" and "CREATE PROC" might save me a few keystrokes, and I'm sure the shorthand equivalents are here to stay, but something just doesn't 
feel right about it.  Same with the parameters for built-in functions like DATEDIFF(), DATEADD() and DATEPART().  Why use WK or DW when you can use WEEK or WEEKDAY?  (I also never understood why WEEKDAY become 
DW in shorthand, instead of WD, which is not supported.  DW likely means DAYOFWEEK but that is an ODBC function and not supported directly in T-SQL at all.  That in and of itself convinced me that it is better to take the 
expensive hit of typing five extra characters to be explicit and clear.)  Finally, I always explicitly say "INNER JOIN or "LEFT OUTER JOIN"... never just "join" or "left join."  Again, no real good reason behind that, just habit.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Using parentheses liberally around AND / OR blocks&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;I always group my clauses when mixing AND and OR.  Leaving it up to the optimizer to determine what "x=5 AND y = 4 OR b = 3" really means is not my cup of tea.  I wrote a &lt;a href="http://databases.aspfaq.com/general/why-do-i-get-weird-results-when-using-both-and-and-or-in-a-query.html" title="http://databases.aspfaq.com/general/why-do-i-get-weird-results-when-using-both-and-and-or-in-a-query.html" target="_blank"&gt;very short article about this&lt;/a&gt; a few years ago.
&lt;/p&gt;

&lt;p&gt;======================
&lt;/p&gt;

&lt;p&gt;So, after all of that, given the procedure I listed at the start of the article, what would I end up with?  Assuming I am using SQL Server 2008, and that I can update the calling application to use the right procedure name, to use 
sensible input parameter names, and to stop using return values instead of output parameters: &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;PROCEDURE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Customer_GetOlderOrders&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@OrderStatus&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@MaxOrderStatus&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@OrderDate&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SMALLDATETIME&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@RC1&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;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT OUTPUT&lt;/font&gt;&lt;font color="black"&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@RC2&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;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT OUTPUT&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SET NOCOUNT ON&lt;/font&gt;&lt;font color="blue"&gt;&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;DECLARE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@City&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;32&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'Beverly'&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@State&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;CHAR&lt;/font&gt;&lt;font color="gray"&gt; (&lt;/font&gt;&lt;font color="black"&gt;2&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'MA'&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@MinOrderCount&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;5&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;c.CustomerID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;c.FirstName&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;c.LastName&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;c.OrderDate&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Customers c&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INNER&amp;nbsp;JOIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Orders&amp;nbsp;o&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;c.CustomerID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;o.CustomerID&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;WHERE&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;o.OrderStatus&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@OrderStatus&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;&lt;/font&gt;&lt;font color="gray"&gt;OR&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;o.OrderStatus&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;&amp;lt;=&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@MaxOrderStatus&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AND&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;o.OrderDate&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;&amp;lt;=&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@MaxOrderDate&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SET&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@RC1&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;@@ROWCOUNT&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;c.CustomerID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;OrderCount&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;COUNT&lt;/font&gt;&lt;font color="gray"&gt;(*)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Customers&amp;nbsp;c&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;LEFT&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;OUTER&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;JOIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Orders&amp;nbsp;o&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;ON&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;c.CustomerID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;o.CustomerID&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;WHERE&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;c.City&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@City&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;AND&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;c.State&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@State&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;GROUP&amp;nbsp;BY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;c.CustomerID&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;HAVING&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;COUNT&lt;/font&gt;&lt;font color="gray"&gt;(*)&amp;nbsp;&amp;gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@MinOrderCount&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SET&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@RC2&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="magenta"&gt;@@ROWCOUNT&lt;/font&gt;&lt;font color="gray"&gt;;
&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;RETURN&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;END&lt;br&gt;&lt;/font&gt;&lt;font color="black"&gt;GO&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Okay, so it LOOKS like a lot more code, because the layout is more vertical.  But you tell me.  Copy both procedures to SSMS or Query Analyzer, and which one is easier to read / understand?  And is it worth the three minutes it took me to convert the original query?&amp;nbsp; It took me a few hours to convert this list from my subconscious to you, so hopefully I have helped you pick up at least one good habit.&amp;nbsp; And if you think any of these are BAD habits, please drop a line and let me know why!
&lt;/p&gt;</description></item><item><title>Let's deprecate UPDATE FROM!</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2008/03/09/lets-deprecate-update-from.aspx</link><pubDate>Sun, 09 Mar 2008 23:38:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:5515</guid><dc:creator>Hugo Kornelis</dc:creator><description>&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;I guess that many people using UPDATE … FROM on a daily basis do so without being aware that they are violating all SQL standards.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;All versions of the ANSI SQL standard that I checked agree that an UPDATE statement has three clauses – the UPDATE clause, naming the table to be updated; the SET clause, specifying the columns to change and their new values; and the optional WHERE clause to filter the rows to be updated. No FROM or JOIN – if you need data from a different table, use a subquery in the SET clause. The optional FROM and JOIN clauses were added by Microsoft, as an extension to the standard syntax (and just to make out lives more interesting, they invented different variations of the syntax for SQL Server and for Access). So when you are in the habit of using them, be prepared to review all your UPDATE statements when moving to Oracle, DB2, Sybase, MySQL, or even a different Microsoft database!&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE:13.5pt;mso-ansi-language:en-gb;"&gt;&lt;FONT face="Times New Roman"&gt;Standards? Bah, who cares?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Well, some do. Me for instance – I will never use proprietary syntax if I know a standard alternative, expect if using the latter has severe negative consequences. And maybe you will, one day, when your boss comes back from the golf course with the great news that he managed to convince a colleague (who just happens to work in an Oracle shop) to buy a copy of your company’s application instead of some off-the-shelf product. Or when there’s a great job opportunity for someone with cross platform skills. Or when you are asked to help out this new colleague with 10+ years of DB2 experience. One of the lesser known side effects of Murphy’s Law is that those who least expect having to move their database to another platform, will.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;But even if you really don’t care about portability, there are other reasons to be wary of using UPDATE FROM. In fact, the most important reason why I dislike UPDATE FROM is not that it’s non-standard, but that it is just too easy to make mistakes with. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE:13.5pt;mso-ansi-language:en-gb;"&gt;&lt;FONT face="Times New Roman"&gt;Correctness? Bah, who cares?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Well, most do. That’s why we test.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;If I mess up the join criteria in a SELECT query so that too many rows from the second table match, I’ll see it as soon as I test, because I get more rows back then expected. If I mess up the subquery criteria in an ANSI standard UPDATE query in a similar way, I see it even sooner, because SQL Server will return an error if the subquery returns more than a single value. But with the proprietary UPDATE FROM syntax, I can mess up the join and never notice – SQL Server will happily update the same row over and over again if it matches more than one row in the joined table, with only the result of the last of those updates sticking. And there is no way of knowing which row that will be, since that depends in the query execution plan that happens to be chosen. A worst case scenario would be one where the execution plan just happens to result in the expected outcome during all tests on the single-processor development server – and then, after deployment to the four-way dual-core production server, our precious data suddenly hits the fan…&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE:13.5pt;mso-ansi-language:en-gb;"&gt;&lt;FONT face="Times New Roman"&gt;That’s all?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Well, almost. There’s one more thing. Probably not something you’ll run into on a daily base, but good to know nonetheless. If the target of the update happens to be a view instead of a base table, and there is an INSTEAD OF UPDATE trigger defined for the view, the UPDATE will fail with this error message:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:8pt;COLOR:red;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;Msg 414, Level 16, State 1, Line 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:8pt;COLOR:red;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;UPDATE is not allowed because the statement updates view "v1" which participates in a join and has an INSTEAD OF UPDATE trigger.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Of course, most people will never run into this. But I did have the misfortune of doing so once – unfortunately, I discovered this limitation &lt;I style="mso-bidi-font-style:normal;"&gt;after&lt;/I&gt; rewriting several hundred ANSI standard UPDATE statements to the equivalent UPDATE FROM, and having to convert them all back after as much as a single test…&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE:13.5pt;mso-ansi-language:en-gb;"&gt;&lt;FONT face="Times New Roman"&gt;And that’s why you want to deprecate UPDATE FROM?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Well, no. The view with INSTEAD OF UPDATE trigger won’t affect many people. And the possibility of error can be somewhat thwarted by making sure (and double-checking) to always include all columns of the primary key (or a unique constraint) of the source table. So we’re back to the more principle point of avoiding proprietary syntax if there is an ANSI standard alternative with no or limited negative consequences. And in the case of UPDATE FROM, there are some cases where the standard syntax just doesn’t cut it.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;One such scenario is when a file is read in periodically with updated information that has to be pushed into the main table. The code below sets up a simplified example of this – a table Customers, with SSN as its primary key, that stores address and lots of other information, and a table Moved, which is the staging table containing the contents of a file received from a third party listing new address for people who recently moved. I have also included the code to preload the tables with some mocked up data – the Customers table has 10,000 rows, and the Moved table has 3,000 rows, 1,000 of which match an existing row in the Customers table. The others don’t – those people are apparently not our customers.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;CREATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;TABLE&lt;/SPAN&gt; Customers&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;SSN &lt;SPAN style="COLOR:blue;"&gt;char&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;9&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Street &lt;SPAN style="COLOR:blue;"&gt;varchar&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;40&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;HouseNo &lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;City &lt;SPAN style="COLOR:blue;"&gt;varchar&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;40&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;LotsOfOtherInfo &lt;SPAN style="COLOR:blue;"&gt;char&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;250&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;DEFAULT &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;''&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;PRIMARY&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;KEY &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;SSN&lt;SPAN style="COLOR:gray;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;CHECK &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;SSN &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;LIKE&lt;/SPAN&gt; &lt;SPAN style="COLOR:red;"&gt;'%[^0-9]%'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;CREATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;TABLE&lt;/SPAN&gt; Moved&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;SSN &lt;SPAN style="COLOR:blue;"&gt;char&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;9&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Street &lt;SPAN style="COLOR:blue;"&gt;varchar&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;40&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;HouseNo &lt;SPAN style="COLOR:blue;"&gt;int&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;City &lt;SPAN style="COLOR:blue;"&gt;varchar&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;40&lt;SPAN style="COLOR:gray;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;PRIMARY&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;KEY &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;SSN&lt;SPAN style="COLOR:gray;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;CHECK &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;SSN &lt;SPAN style="COLOR:gray;"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;LIKE&lt;/SPAN&gt; &lt;SPAN style="COLOR:red;"&gt;'%[^0-9]%'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;INSERT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;INTO&lt;/SPAN&gt; Customers&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;SSN&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; Street&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; HouseNo&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; City&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;RIGHT(&lt;/SPAN&gt;Number&lt;SPAN style="COLOR:gray;"&gt;+&lt;/SPAN&gt;1000000000&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;9&lt;SPAN style="COLOR:gray;"&gt;),&lt;/SPAN&gt; &lt;SPAN style="COLOR:red;"&gt;'Street '&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;+&lt;/SPAN&gt; &lt;SPAN style="COLOR:fuchsia;"&gt;CAST&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;Number &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;varchar&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;10&lt;SPAN style="COLOR:gray;"&gt;)),&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Number&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR:red;"&gt;'City '&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;+&lt;/SPAN&gt; &lt;SPAN style="COLOR:fuchsia;"&gt;CAST&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;Number &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;varchar&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;10&lt;SPAN style="COLOR:gray;"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;dbo&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;Numbers&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;Number &lt;SPAN style="COLOR:gray;"&gt;BETWEEN&lt;/SPAN&gt; 1 &lt;SPAN style="COLOR:gray;"&gt;AND&lt;/SPAN&gt; 30000&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;AND&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Number &lt;SPAN style="COLOR:gray;"&gt;%&lt;/SPAN&gt; 3 &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; 0&lt;SPAN style="COLOR:gray;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;INSERT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;INTO&lt;/SPAN&gt; Moved&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;SSN&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; Street&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; HouseNo&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; City&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;SELECT&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;RIGHT(&lt;/SPAN&gt;Number&lt;SPAN style="COLOR:gray;"&gt;+&lt;/SPAN&gt;1000000000&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt;9&lt;SPAN style="COLOR:gray;"&gt;),&lt;/SPAN&gt; &lt;SPAN style="COLOR:red;"&gt;'&lt;st1:address&gt;New street&lt;/st1:address&gt; '&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;+&lt;/SPAN&gt; &lt;SPAN style="COLOR:fuchsia;"&gt;CAST&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;Number &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;varchar&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;10&lt;SPAN style="COLOR:gray;"&gt;)),&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Number &lt;SPAN style="COLOR:gray;"&gt;*&lt;/SPAN&gt; 2&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR:red;"&gt;'New city '&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;+&lt;/SPAN&gt; &lt;SPAN style="COLOR:fuchsia;"&gt;CAST&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;Number &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;varchar&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;10&lt;SPAN style="COLOR:gray;"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;dbo&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;Numbers&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;Number &lt;SPAN style="COLOR:gray;"&gt;BETWEEN&lt;/SPAN&gt; 1 &lt;SPAN style="COLOR:gray;"&gt;AND&lt;/SPAN&gt; 30000&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;AND&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Number &lt;SPAN style="COLOR:gray;"&gt;%&lt;/SPAN&gt; 10 &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; 0&lt;SPAN style="COLOR:gray;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;go&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Since ANSI-standard SQL does not allow a join to be used in the UPDATE statement, we’ll have to use subqueries to find the new information, &lt;B style="mso-bidi-font-weight:normal;"&gt;and&lt;/B&gt; to find the rows that need to be updated, resulting in this query:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;UPDATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; Customers&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Street&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;st1:address&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&lt;/SPAN&gt; Street&lt;/st1:address&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Moved &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; m&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; Customers&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN&lt;SPAN style="COLOR:gray;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;HouseNo &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&lt;/SPAN&gt; HouseNo&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Moved &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; m&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; Customers&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN&lt;SPAN style="COLOR:gray;"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;City&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&lt;/SPAN&gt; City&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Moved &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; m&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; Customers&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;EXISTS&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;*&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Moved &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; m&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; Customers&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN&lt;SPAN style="COLOR:gray;"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;There’s a lot of duplicated code in here. And if we were getting data from a complicated subquery instead of the table Moved, it would be even worse (though we can at least put all the duplicated code in a CTE since SQL Server 2005). Of course, writing the code is done quickly enough once you master the use of copy and paste, but the code has to be maintained as well.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Maybe even worse is that the performance of this query just sucks – if you run this (enclosed in a BEGIN TRAN / ROLLBACK TRAN, so you can run the variations below without having to rebuild the original data) and check out the execution plan, you’ll see that the optimizer needs no less than five table scans (one for Customers, and four for Moved) and four merge join operators. And that, too, would be much worse if the source of the data had been a complex subquery (and no, using a CTE will not help the optimizer find a better plan – it just doesn’t understand that the four subqueries are similar enough that they can be collapsed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Now, if Microsoft had chosen to implement row-value constructors (as defined in the ANSI standard), we could have simplified this to&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;UPDATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; Customers&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;SET&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;Street&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; HouseNo&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; City&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;st1:address&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&lt;/SPAN&gt; Street&lt;/st1:address&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; HouseNo&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; City&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Moved &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; m&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; Customers&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN&lt;SPAN style="COLOR:gray;"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;EXISTS&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN style="COLOR:gray;"&gt;*&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Moved &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; m&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&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;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;WHERE&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN &lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; Customers&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN&lt;SPAN style="COLOR:gray;"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;But this is invalid syntax in any version of SQL Server (including the latest CTP for SQL Server 2008), and I know of no plans to change that before SQL Server 2008 RTMs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;But with using the proprietary UPDATE FROM syntax, we can simplify this, and get a much better performance to boot. Here’s how the same update is written in non-portable code:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;UPDATE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;c&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Street&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;Street&lt;SPAN style="COLOR:gray;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;HouseNo&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;HouseNo&lt;SPAN style="COLOR:gray;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;City&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;City&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;FROM&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Customers &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; c&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;INNER&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;JOIN&lt;/SPAN&gt; Moved&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; m&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;ON&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; c&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN&lt;SPAN style="COLOR:gray;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;And now, the optimizer will produce a plan that scans each table only once and has only a single merge join operator. Some quick tests (with much more rows in the tables) show that it executes two to three times quicker than the ANSI standard version. For that performance gain, I will gladly choose the proprietary syntax over the standard!&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE:13.5pt;mso-ansi-language:en-gb;"&gt;&lt;FONT face="Times New Roman"&gt;What’s with the title of this post then? Why deprecate a fine feature?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Patience, we’re getting there. Bear with me.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;All the above is true for versions of SQL Server up to SQL Server 2005. But SQL Server 2008 will change the playing field. It introduces a new statement, MERGE, that is specifically designed for situations where rows from a table source either have to be inserted into a destination table, or have to be used to update existing rows in the destination table. However, there is no law that prescribes that any MERGE should always actually include both an insert and an update clause – so with this new statement, we can now rewrite the above code as follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;MERGE&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;INTO&lt;/SPAN&gt; Customers &lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; c&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;USING&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Moved&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;AS&lt;/SPAN&gt; m&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:blue;"&gt;ON&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; c&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;SSN&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;WHEN&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;MATCHED&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;THEN&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;UPDATE&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Street&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;Street&lt;SPAN style="COLOR:gray;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;HouseNo&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;HouseNo&lt;SPAN style="COLOR:gray;"&gt;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;City&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;=&lt;/SPAN&gt; m&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;City&lt;SPAN style="COLOR:gray;"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;As you can see, the source table and the join criteria are included only once, just as in the proprietary UPDATE FROM. The execution plan (tested on the February CTP, also known as CTP6) is also quite similar, including just a few extra operators that are specific to the new MERGE statement. What really surprised me, was that the plan for the MERGE statement was estimated to be about 65% cheaper (faster) than the corresponding UPDATE FROM statement. However, I think SQL Server is lying here – a quick test with more data shows only an extremely marginal advantage of MERGE over UPDATE FROM. This test was too limited to draw serious conclusions, but I am quite sure that there will not be a 65% saving by using MERGE over UPDATE FROM. (I do expect such a saving form either MERGE or UPDATE FROM over the ANSI-compliant UPDATE statement for this case).&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;The good news is that:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;TEXT-INDENT:-18pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt;"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;SPAN style="mso-list:ignore;"&gt;&lt;FONT size=3&gt;1)&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;The MERGE statement is described in SQL:2003 and can thus be considered ANSI standard. (In fact, SQL Server implements a superset of the ANSI standard MERGE syntax: everything described in the syntax is implemented, but there are some non-standard extensions that make the command even more useful as well. However, the example above uses only the standard features and should hence run on each DBMS that conforms to the SQL:2003 version of MERGE).&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;TEXT-INDENT:-18pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt;"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;SPAN style="mso-list:ignore;"&gt;&lt;FONT size=3&gt;2)&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;The MERGE statement will return an error message if I mess up my join criteria so that more than a single row from the source is matched:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:8pt;COLOR:red;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;Msg 8672, Level 16, State 1, Line 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="FONT-SIZE:8pt;COLOR:red;FONT-FAMILY:'Courier New';mso-ansi-language:en-us;mso-fareast-language:en-us;mso-no-proof:yes;"&gt;The MERGE statement attempted to UPDATE or DELETE the same row more than once. This happens when a target row matches more than one source row. A MERGE statement cannot UPDATE/DELETE the same row of the target table multiple times. Refine the ON clause to ensure a target row matches at most one source row, or use the GROUP BY clause to group the source rows.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 36pt;TEXT-INDENT:-18pt;mso-list:l0 level1 lfo1;tab-stops:list 36.0pt;"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;SPAN style="mso-list:ignore;"&gt;&lt;FONT size=3&gt;3)&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;The MERGE statement will gladly accept a view with an INSTEAD OF UPDATE trigger as the target of the update.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;So as you see, MERGE allows me to achieve what I previously could achieve only with an ANSI standard UPDATE statement with lots of duplicated code and lousy performance, or with a UPDATE FROM statement that hinders portability, introduces a higher than normal risk of errors going unnoticed through QA right into the production database, and has some odd limitation on views with INSTEAD OF UPDATE triggers. None of these downsides and limitations apply to MERGE. And if there are any other problems with MERGE, I have yet to find them.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Times New Roman';mso-ansi-language:en-us;mso-fareast-language:nl;mso-fareast-font-family:'Times New Roman';mso-bidi-language:ar-sa;"&gt;With this alternative available, I fail to see any reason why the proprietary UPDATE FROM syntax should be maintained. In my opinion, it can safely be marked as deprecated in SQL Server 2008. It should of course still work, as “normal” supported syntax in both SQL Server 2008 and the next version, and in at least one version more if the database is set to a lower compatibility – but it should be marked as deprecated, and it should eventually be removed from the product. Why waste resources on maintaining that functionality, when there is an alternative that is better in every conceivable way? I’d much rather see the SQL Server team spend their time and energy on more important stuff, such as full support for row-value constructors and full support for the OVER() clause. Or maybe even on releasing Service Pack 3 for SQL Server 2005!&lt;/SPAN&gt;&lt;/P&gt;</description></item><item><title>Nondeterministic UPDATE</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2007/11/13/nondeterministic-update.aspx</link><pubDate>Tue, 13 Nov 2007 19:15:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:3312</guid><dc:creator>Linchi Shea</dc:creator><description>&lt;P&gt;Under the description for UPDATE in SQL Server &lt;A href="http://msdn2.microsoft.com/en-us/library/aa260662(SQL.80).aspx"&gt;2000&lt;/A&gt; and &lt;A href="http://msdn2.microsoft.com/en-us/library/ms177523.aspx"&gt;2005&lt;/A&gt; Books Online, you can find the following statement (thanks to SQL Server MVP Steve Kass for pointing me to this passage):&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;The results of an UPDATE statement are undefined if the statement includes a FROM clause that is not specified in such a way that only one value is available for each column occurrence that is updated, that is if the UPDATE statement is not deterministic.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;BOL goes on to give a simple example of such an UPDATE. However, the example doesn't give you a real feel for the nondeterministic behavior. Although the result is supposed to be undefined and indeed you don't know&amp;nbsp;what value UPDATE will end up assigning, the result does come out consistently the same no matter how many times you execute it. At least during my limited number of test runs, UPDATE seems to always pick the first value. But of course you can't count on that because a different execution plan may pick a different value.&lt;/P&gt;
&lt;P&gt;Still, it would be nice to see a nondeterministic UPDATE statement actually picks a different value to drive it home that you should not use it in your app, unless of course your app logic wants to take advantage of this particular non-determinism (which is difficult to imagine).&lt;/P&gt;
&lt;P&gt;Recently, however, I happened to run into an interesting case where the nondeterministic behavior of UPDATE can be easily reproduced on a multi-core server when query parallelism is used. Here's the script to see the behavior.&lt;/P&gt;
&lt;P&gt;First, run the following script to create two tables and a stored procedure in any user database on a SQL Server 2005 instance:&lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR:#dddddd;"&gt;&lt;PRE&gt;CREATE TABLE t1 (
	c1 int         NULL,
	c2 varchar(50) NULL,
	rate int       NULL
)
go
CREATE INDEX c1_ind ON t1 (c1)
go

CREATE TABLE t2 (
	c1 int           NULL,
	c2 varchar(50)   NULL,
	rate int         NOT NULL
)
go

drop proc testProc
go
create proc testProc
as
set nocount on
begin tran
  UPDATE t1
     SET rate = t2.rate
    FROM t1 With (Index (c1_ind)), t2
   WHERE t1.c1 = t2.c1
     and t1.c2 = t2.c2

  SELECT 'count_0' = count(*) FROM t1 WHERE rate = 0;
  SELECT 'count_1' = count(*) FROM t1 WHERE rate = 1;
  SELECT 'rate_sum' = sum(rate) FROM t1
rollback tran
go&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Second, populate the two tables with data using the following script:&lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR:#e8e8e8;"&gt;&lt;PRE&gt;WITH tmp (c1, c2,c3) as (
    SELECT 1,1,1
    UNION ALL
    SELECT cast(rand(c3)*1000000 as int)%200, 
           cast(rand(c3)*1000000 as int)%200, 
           c3 + 1
      FROM tmp
     WHERE c3 &amp;lt; 100000
)
INSERT t1
SELECT c1, CAST(c2 as varchar(50)), NULL
  FROM tmp
OPTION (maxrecursion 0);

WITH tmp (c1, c2, c3) as (
    SELECT 0,0,0
    UNION ALL
    SELECT c1 + 1, c2 + 1, c3 + 1
      FROM tmp
     WHERE c1 &amp;lt; 200
)
INSERT t2
SELECT cast(c1 as char(6)), 
       cast(c2 as varchar(50)), 
       0                         -- c3 value = 0
  FROM tmp
OPTION (maxrecursion 0);

-- give each c1 value a second c3 value = 1
INSERT t2
SELECT c1, c2, 1
  FROM t2;
go
&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Finally, run the stored procedure multiple times to see that different results are produced: &lt;/P&gt;
&lt;DIV style="BACKGROUND-COLOR:#e5e5e5;"&gt;EXEC testProc;&lt;/DIV&gt;
&lt;P&gt;Apparently, nondeterminism in query processing gives rise to the different results. A few observations are noteworthy:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The non-determinstic behavior is not a result of different query execution plan. At least, the reported execution plan&amp;nbsp;remains the same for all my test runs.&lt;/LI&gt;
&lt;LI&gt;If you disable query parallelism by setting &lt;U&gt;max degree of parallelism&lt;/U&gt; to 1, the stored procedure will produce the same results.&lt;/LI&gt;
&lt;LI&gt;On a SQL Server 2000 instance, you probably won't get a parallel plan, and thus won't see different results.&lt;/LI&gt;
&lt;LI&gt;The size of the table t1 is significant. On my test server, populating table t1 with 70,000 still leads to a parallel query plan, thus different results in multiple executions of the stored procedure. But if I only populate the table with 50,000 rows, I don't get an query parallelism, and I get consistent results. So SQL Server query optimizer is sensitive to the table size in deciding whether to use a parallel plan.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description></item><item><title>T-SQL Cursors -- the Case of the Published TPC-E Tests</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2007/10/08/t-sql-cursors-the-case-of-the-published-tpc-e-tests.aspx</link><pubDate>Tue, 09 Oct 2007 03:39:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2909</guid><dc:creator>Linchi Shea</dc:creator><description>&lt;P&gt;Within the SQL Server community, there is so much publicity on T-SQL set-oriented processing as good practice and the use of T-SQL cursors as bad practice that&amp;nbsp; T-SQL cursors are effectively being seen as a plague to be avoided when in fact it's not the use of T-SQ cursors, but their misuse, that should be avoided. To be fair, I must say that I have seen set-minded folks coming out to exhibit a more balanced view.&lt;/P&gt;
&lt;P&gt;I'm not here to engage in a new debate on the pros and cons of T-SQL cursors or when they should be used. Such a debate is necessarily a contentious one at the best, and the voice for the set-oriented approach is so loud that any other arguments or suggestions risk getting drowned out.&lt;/P&gt;
&lt;P&gt;What I do want to highlight in this post is that T-SQL cursors are used heavily in all the three TPC-E test results published to date (see &lt;A href="http://www.tpc.org/"&gt;www.tpc.org&lt;/A&gt;). As of 2007/10/09, all the published TPC-E official tests were obtained with SQL Server 2005 X64 edition and with essentially the same database schema. If you look at the full disclosure reports for these TPC-E results (available at &lt;A href="http://www.tpc.org/"&gt;www.tpc.org&lt;/A&gt;), you'll find the stored procedures that were written to implement the TPC-E transactions, and of the 26 stored procedures, nine used T-SQL cursors.&lt;/P&gt;
&lt;P&gt;Of course, the fact that these TPC-E implementations used T-SQL cursors doesn't mean that T-SQL cursors should be generally recommended. But these published TPC-E results do serve as a few data points to highlight the traps of such unqualified statement as "avoid using cursors."&lt;/P&gt;
&lt;P&gt;Yeah, the fact that these TPC-E implementations used T-SQL cursors doesn't even mean cursors are the best possible solution for their business logic. However, note that TPC benchmarking is a highly competitive business. Significant resources are being invested by the test sponsors and the DBMS vendors to get the best performance numbers for their respective systems. You can safely assume that whatever design and configurations that are used in a published TPC benchmark are not there by accident, but are deliberately chosen after many alternative designs and configurations have been explored, considered, and tested.&lt;/P&gt;</description></item><item><title>How NOT to pass a lot of parameters</title><link>http://sqlblog.com/blogs/hugo_kornelis/archive/2007/10/04/how-not-to-pass-a-lot-of-parameters.aspx</link><pubDate>Thu, 04 Oct 2007 07:07:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:2862</guid><dc:creator>Hugo Kornelis</dc:creator><description>&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Did you know that SQL Server allows stored procedures to have up to 2100 parameters? And more important: do you care? Well, some people do care, and &lt;/FONT&gt;&lt;A href="http://www.celko.com/"&gt;&lt;FONT face="Times New Roman" color=#800080 size=3&gt;Joe Celko&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt; seems to be one of them.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;If you are a regular reader of SQL Server newsgroups, you probably know Joe Celko from his always unfriendly and often incorrect replies. Here is a typical example, one that I have seen several times recently, in a paraphrased form:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 35.4pt;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;Question&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;: I want to send a list of values to my stored procedure, but &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-gb;mso-no-proof:yes;"&gt;WHERE ColumnName IN (@ValueList)&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt; does not work – how to solve this?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt 35.4pt;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;Answer&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;: SQL Server can handle over 1000 parameters. You should use &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-gb;mso-no-proof:yes;"&gt;WHERE ColumnName IN (@Parm1, @Parm2, …, @ParmN)&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT face="Times New Roman" size=3&gt;Joe Celko is the only one I have ever seen giving this advise. Many people will then jump into the discussion, challenging Joe’s advise. To which Joe will always reply that he has received a smart stored procedure that will solve a &lt;/FONT&gt;&lt;A href="http://en.wikipedia.org/wiki/Sudoku"&gt;&lt;FONT face="Times New Roman" color=#800080 size=3&gt;Sudoku&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt; puzzle, and that takes 81 parameters (one for each cell in the puzzle) as its input – unfortunately, Joe has so far refused to actually publish his code to let other people verify his claims.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE:13.5pt;mso-ansi-language:en-gb;"&gt;&lt;FONT face="Times New Roman"&gt;The test setup&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;I still wanted to see for myself how passing 81 parameters into a stored procedure compares to other methods of passing in the same input, so I wrote three simple test procedures. Each of these procedures takes a Sudoku puzzle as input, but in three different forms. Each of the three then uses the input to populate a temporary table (#Problem) with the puzzle, and then performs a pretty standard pivot query to output the puzzle in the usual form.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;After verifying that all of the procedures worked as expected, I uncommented the pivot query to reduce the output for my performance tests. I then set the tests. I selected two real Sudoku puzzles (an easy one, with 34 cells given, and a hard one with only 27 cells given) and added two nonsensical ones of my own (one with only 5 cells given, and one with 72 cells). For each combination of a puzzle and a procedure, I coded a loop that calls the procedure a thousand times and records the elapsed time in a table. These twelve loops were than enclosed in an endless loop. Once satisfied with the code, I hit the execute button, pushed my laptop out of the way and went on to other stuff.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;mso-layout-grid-align:none;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-ansi-language:en-us;"&gt;Some 24-odd hours later, I interrupted the test script. Each of the twelve “thousand calls” tests had been executed 400 times. I dusted of a query I originally wrote for testing the performance of code for the Spatial Data chapter in “Expert SQL Server 2005 Development” to calculate the average duration per single call, disregarding the fastest and slowest 10% of the measurements to exclude the influence of semi-random other activities on my laptop.&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:8pt;FONT-FAMILY:'Courier New';mso-ansi-language:en-gb;mso-no-proof:yes;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;(Note that all code to create the stored procedures and run the tests is in the attachment to this post, so you can always repeat these tests on your machine.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE:13.5pt;mso-ansi-language:en-gb;"&gt;&lt;FONT face="Times New Roman"&gt;The contenders&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;The first contender is of course the procedure with 81 parameters that Joe Celko is such an avid fan of. Creating this procedure involved a lot of copying and pasting, a lot of editing numbers in the copied and pasted code, and a lot of tedious debugging until I had finally found and corrected all locations where I had goofed up the copy and paste or where I had failed to edit a number after pasting. The resulting code is very long, tedious to read and maintain, and screams “Hey! You forgot to normalize these repeating groups into their own table” all the way. Manually typing the EXEC statements to call this procedure with test data was also very cumbersome and error-prone. In a real situation, the procedure would probably be called from some user-friendly front end code. I’m far from an expert in front end code, but I expect this code to be very long as well, since it has to check and optionally fill and pass 81 parameters.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT face="Times New Roman" size=3&gt;The second contender uses a pretty standard CSV string as input, with the additional requirement that each value in the CSV is three characters: row@, column#, value. The procedure uses a variation of one of the scripts found on &lt;/FONT&gt;&lt;A href="http://www.sommarskog.se/arrays-in-sql.html"&gt;&lt;FONT face="Times New Roman" color=#800080 size=3&gt;Erland Sommarskog’s site&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt; to parse the CSV list into a tabular format. This code is lots shorter, and as a result easier on the eyes and easier to maintain. Typing in the EXEC statements for testing is still pretty cumbersome (though I found a way to cheat – simply copy the parameter list for the Celko version, do some global search and replace to remove various characters, and the end was exactly the string I needed to call this procedure). The front end code will probably be lots shorter, since it can use a simple loop to process the input and build the CSV parameter.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;The third and last contender takes a CHAR(81) parameter as input. The first 9 characters of this parameter describe the top row, using a space to depict an empty cell; the second set of 9 characters is for the second row, and so forth. Parsing this parameter turned out to be even easier than parsing the CSV parameter. Another observation I made is that is was much easier to manually enter the parameter for the tests – just read the puzzle left to right and bottom to top and type either a number or a space for each cell. This was absolutely painless, and I didn’t make a single mistake. Of course, this is irrelevant for the expected real situation where the parameter is built by the front end – the code to do this will probably be about as complex as that for the CSV parameter.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE:13.5pt;mso-ansi-language:en-gb;"&gt;&lt;FONT face="Times New Roman"&gt;Performance results&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;If you’re as eager to see the test results, you’ll probably have skipped the previous section. No problem, just promise to go back and read it later, m’kay?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV align=center&gt;
&lt;TABLE class=MsoTableGrid style="BORDER-RIGHT:medium none;BORDER-TOP:medium none;BORDER-LEFT:medium none;WIDTH:383.4pt;BORDER-BOTTOM:medium none;BORDER-COLLAPSE:collapse;mso-border-alt:solid windowtext .5pt;mso-yfti-tbllook:480;mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-border-insideh:.5pt solid windowtext;mso-border-insidev:.5pt solid windowtext;" cellSpacing=0 cellPadding=0 class="MsoTableGrid"&gt;

&lt;TR style="mso-yfti-irow:0;mso-yfti-firstrow:yes;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:windowtext 1pt solid;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:windowtext 1pt solid;WIDTH:126.95pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Test version&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:windowtext 1pt solid;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:85.45pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Joe Celko’s 81 parameters&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:windowtext 1pt solid;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:72pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Single CSV parameter&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:windowtext 1pt solid;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:99pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Single CHAR(81) parameter&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:1;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:windowtext 1pt solid;WIDTH:126.95pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Almost empty (5 cells)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:85.45pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;1.08 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:72pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;1.40 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:99pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;1.05 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:2;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:windowtext 1pt solid;WIDTH:126.95pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Hard puzzle (27 cells)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:85.45pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;1.80 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:72pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;1.78 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:99pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;1.35 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:3;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:windowtext 1pt solid;WIDTH:126.95pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Easy puzzle (34 cells)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:85.45pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;2.04 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:72pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;1.90 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:99pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;1.45 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="mso-yfti-irow:4;mso-yfti-lastrow:yes;"&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:windowtext 1pt solid;WIDTH:126.95pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Almost full (72 cells)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:85.45pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;3.34 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:72pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;2.56 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD class="" style="BORDER-RIGHT:windowtext 1pt solid;PADDING-RIGHT:5.4pt;BORDER-TOP:#d4d0c8;PADDING-LEFT:5.4pt;PADDING-BOTTOM:0cm;BORDER-LEFT:#d4d0c8;WIDTH:99pt;PADDING-TOP:0cm;BORDER-BOTTOM:windowtext 1pt solid;BACKGROUND-COLOR:transparent;mso-border-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .5pt;"&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;TEXT-ALIGN:center;" align=center&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;1.99 ms&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;As you see, using lots of parameters is faster than using a single CSV parameter only if you don’t actually pass values in these parameters. As soon as you &lt;B style="mso-bidi-font-weight:normal;"&gt;&lt;I style="mso-bidi-font-style:normal;"&gt;use&lt;/I&gt;&lt;/B&gt; the parameters, performance of a procedure with lots of parameters deteriorates quickly.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;You can also see that the CHAR(81) parameter wins in all cases.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE:13.5pt;mso-ansi-language:en-gb;"&gt;&lt;FONT face="Times New Roman"&gt;Network bandwidth&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;My testing was all carried out on my laptop. The results will for the most part me a result of the time needed to process the input, not on network capacity. However, it is easy to see by just looking at the EXEC statements that the CHAR(81) version uses the least network resources, Celko’s version with 81 parameters uses the most, and the CSV versions sits nicely in between.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE:13.5pt;mso-ansi-language:en-gb;"&gt;&lt;FONT face="Times New Roman"&gt;Final thoughts&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;You may have noted that I have not included a version with an XML input parameter in my tests. I probably should have done that, but I have to admit that I still have so much to learn on how to handle XML in a SQL Server database that I didn’t feel comfortable enough to sit down and write one myself. But your submissions are welcomed – if you feel that you can write an efficient version of this procedure that accepts its input in XML format, do not hesitate to write me. As soon as I can spare the time to set up the laptop for another all-nighter of performance testing, I’ll rerun the script with your XML solution included and post the results back to this site,&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;While writing this post, I found a newsgroup posting by Joe Celko where he reveals a snippet of “his” Sudoku solver. And guess what? I was wrong when I thought that I could guess how his procedure looks. It turns out that he does not use defaults for his parameter; you always have to supply them all, using 0 for an empty cell. I didn’t want to repeat all the tests at this time. I expect that this will reduce performance even more, though not by much – but it will also cause a huge increase in network usage!&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;I also saw that the parameters in Joe Celko’s version were declared as integer, so that each parameter will use 4 bytes instead of just 1. This will definitely affect both the performance of the procedure and the network pressure.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE:13.5pt;mso-ansi-language:en-gb;"&gt;&lt;FONT face="Times New Roman"&gt;Conclusion&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;If you have to pass a long list of parameters to a stored procedure or function, you should not use a long collection of parameters. It makes the code harder to write and maintain, prone to subtle errors, longer (which will affect parse and compile time, though I did not include this in my test), uses far more network resources than any of the other alternatives (except, maybe, XML), and gets terribly slow as more parameters are actually used.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;Joe celko will probably find that he too can shorten the amount of code in his Sudoku solver *and* increase performance by using a different strategy to pass the puzzle. Of course, in the case of solving a Sudoku, those two 2 milliseconds extra execution time won’t really matter, not the few hundred extra bytes travelling over the network. But if you ever encounter a similar multi-parameter problem in a procedure that will be called from a web page that will get hundreds of hits per second, those 2 milliseconds and those extra bytes in the network can suddenly become a huge bottleneck!&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0cm 0cm 0pt;"&gt;&lt;SPAN style="mso-ansi-language:en-gb;"&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;SQL Server may support up to 2100 parameters – but that does not imply that it is a good idea to actually use them!&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;</description></item></channel></rss>