<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.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>Using TSQL Variables: Subtle BUG when assigning values to Variables via a Query</title><link>http://blogs.msdn.com/b/davidlean/archive/2009/08/22/using-tsql-variables-subtle-bug-when-assigning-values-to-variables-via-a-query.aspx</link><description>I’m unsure if this is a BUG or “By Design” but for me it is unexpected &amp;amp; likely to cause your application to hang if you aren’t aware of it. So one more article in my “TSQL Best Practise” or “Good TSQL Coding Standards” posts. Summary: If you assign</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Using TSQL Variables: Subtle BUG when assigning values to Variables via a Query</title><link>http://blogs.msdn.com/b/davidlean/archive/2009/08/22/using-tsql-variables-subtle-bug-when-assigning-values-to-variables-via-a-query.aspx#9889376</link><pubDate>Mon, 31 Aug 2009 18:09:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9889376</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;I make sure to reset my variables to NULL when I am going to use SELECT to set a variable or I just use SET. &amp;nbsp;This has been true since at least SQL Server 2000.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9889376" width="1" height="1"&gt;</description></item><item><title>re: Using TSQL Variables: Subtle BUG when assigning values to Variables via a Query</title><link>http://blogs.msdn.com/b/davidlean/archive/2009/08/22/using-tsql-variables-subtle-bug-when-assigning-values-to-variables-via-a-query.aspx#9889197</link><pubDate>Mon, 31 Aug 2009 05:55:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9889197</guid><dc:creator>ALOJ</dc:creator><description>&lt;p&gt;IE 7 shows javascript error and does not post comments to this blog. FF works though.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9889197" width="1" height="1"&gt;</description></item><item><title>re: Using TSQL Variables: Subtle BUG when assigning values to Variables via a Query</title><link>http://blogs.msdn.com/b/davidlean/archive/2009/08/22/using-tsql-variables-subtle-bug-when-assigning-values-to-variables-via-a-query.aspx#9889196</link><pubDate>Mon, 31 Aug 2009 05:54:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9889196</guid><dc:creator>ALOJ</dc:creator><description>&lt;p&gt;There is some related discussion here:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.sqlservercentral.com/Forums/Topic708753-338-1.aspx"&gt;http://www.sqlservercentral.com/Forums/Topic708753-338-1.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;One more options .. you could use statement like this &lt;/p&gt;
&lt;p&gt;set @x = (select 1 where 2=3)&lt;/p&gt;
&lt;p&gt;to be sure that you get NULL back when there will be nothing returned by &amp;quot;SELECT&amp;quot;&lt;/p&gt;
&lt;p&gt;One benefit of the above is ..that it will crash if &amp;quot;select&amp;quot; return more than 1 row .. vs. quietly fetching the first row in the resultset&lt;/p&gt;
&lt;p&gt;.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9889196" width="1" height="1"&gt;</description></item></channel></rss>