Select “where clause” evaluation order

前端 未结 7 1575
梦毁少年i
梦毁少年i 2020-12-06 09:40

In Sql Server 2005 when I have multiple parameters do I have the guarantee that the evaluation order will always be from left to right?

Using an exa

相关标签:
7条回答
  • 2020-12-06 10:07

    One way to control the evaluation order is with the CASE expression.

    [Edit]

    The popular opinion I was trying to express was:

    You cannot depend on expression evaluation order for things like “WHERE OR “, since the optimizer might choose a plan that evaluates the second predicate before the first one. But order of evaluation of the expressions in a CASE statement is fixed, so you can depend on deterministic short circuit evaluation of a CASE statement.

    It does get a bit more complicated than that as explained in the site below:

    http://blogs.msdn.com/b/bartd/archive/2011/03/03/don-t-depend-on-expression-short-circuiting-in-t-sql-not-even-with-case.aspx

    0 讨论(0)
提交回复
热议问题