<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.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>Database Programming: Operator Precedence In SQL Server</title><link>http://blogs.technet.com/wardpond/archive/2008/05/06/database-programming-operator-precedence-in-sql-server.aspx</link><description>[UPDATED 9 May 2008; the information presented doesn't exactly answer Greg's question. There's an update here ; and DTS is discussed here ] I received an inquiry yesterday from Greg Husemeier, who I met when he came to Redmond for the SQL Ranger program.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Database Programming: Operator Precedence In SQL Server</title><link>http://blogs.technet.com/wardpond/archive/2008/05/06/database-programming-operator-precedence-in-sql-server.aspx#3051129</link><pubDate>Tue, 06 May 2008 20:32:40 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3051129</guid><dc:creator>Scott R.</dc:creator><description>&lt;p&gt;If I am summarizing the changes correctly (based on your excerpt above), the only difference is when the unary + and - operators get evaluated:&lt;/p&gt;
&lt;p&gt;- &amp;nbsp;In SQL 2000, they are evaluated first (before any other operators)&lt;/p&gt;
&lt;p&gt;- &amp;nbsp;In SQL 2005, they are evaluated after modulo (%) and before addition (+) operators&lt;/p&gt;
&lt;p&gt;All other operators appear to evaluate in the same precendence order with respect to each other.&lt;/p&gt;
&lt;p&gt;The example expression highlighted in green above (A &amp;lt;&amp;gt; 0 AND B / A &amp;gt; 1) is said to evaluate differently in SQL 2000 and SQL 2005, but I don't see any ungrouped use of the unary + or - that would affect their evaluation.&lt;/p&gt;
&lt;p&gt;Did I miss something in this example?&lt;/p&gt;
&lt;p&gt;Scott R.&lt;/p&gt;</description></item><item><title>re: Database Programming: Operator Precedence In SQL Server</title><link>http://blogs.technet.com/wardpond/archive/2008/05/06/database-programming-operator-precedence-in-sql-server.aspx#3051160</link><pubDate>Tue, 06 May 2008 21:31:16 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3051160</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi Ward,&lt;/p&gt;
&lt;p&gt;As far as I know there is no such thing as implicit order of operations for ANDed predicates -- only OR'd. &amp;nbsp;And if you do want to force the order, parens won't do it, as the QO is smart enough to know how to remove them; you need to use a CASE expression.&lt;/p&gt;
&lt;p&gt;Note that the only time I've ever seen this needed is when someone is trying to work around a bad EAV design and a string column that can contain all sorts of values is implicitly getting converted to a number in the wrong order, e.g.:&lt;/p&gt;
&lt;p&gt;SELECT &lt;/p&gt;
&lt;p&gt; &amp;nbsp;EntityId&lt;/p&gt;
&lt;p&gt;FROM MyEAV&lt;/p&gt;
&lt;p&gt;WHERE&lt;/p&gt;
&lt;p&gt; &amp;nbsp;AttributeName = 'Price'&lt;/p&gt;
&lt;p&gt; &amp;nbsp;AND AttributeValue = 36.25&lt;/p&gt;
&lt;p&gt;Depending on which index the optimizer decides to use, this may fail as the query processor tries to convert the &amp;quot;Product Name&amp;quot; attribute values to NUMERIC...&lt;/p&gt;</description></item><item><title>Database Programming: Operator Precedence In SSIS</title><link>http://blogs.technet.com/wardpond/archive/2008/05/06/database-programming-operator-precedence-in-sql-server.aspx#3051174</link><pubDate>Tue, 06 May 2008 22:11:29 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3051174</guid><dc:creator>Ward Pond's SQL Server blog</dc:creator><description>&lt;p&gt;This morning's post on Operator Precedence was a little misleading, as Scott pointed out in his comment:&lt;/p&gt;
</description></item><item><title>Database Programming: Operator Precedence in DTS is a Matter of Inheritance</title><link>http://blogs.technet.com/wardpond/archive/2008/05/06/database-programming-operator-precedence-in-sql-server.aspx#3053196</link><pubDate>Sat, 10 May 2008 02:32:24 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3053196</guid><dc:creator>Ward Pond's SQL Server blog</dc:creator><description>&lt;p&gt;This post will (hopefully) close a thread which runs here and here . When we last addressed this issue,&lt;/p&gt;
</description></item></channel></rss>