0

I find this hard to test/research so im asking: In a OR similar to where (1 = 1) OR (column1 = @value) condition, will the second part, eg: column1 = @value ever be tested? If possible please provide documentation...

Leonardo
  • 10,737
  • 10
  • 62
  • 155
  • 1
    It's called short-circuiting, which SQL Server does *not* do. See http://stackoverflow.com/questions/11219791/or-operator-short-circuit-in-sql-server and http://weblogs.sqlteam.com/jeffs/archive/2008/02/22/sql-server-short-circuit.aspx – LittleBobbyTables - Au Revoir Apr 11 '14 at 18:04
  • 1
    Check [this question](http://dba.stackexchange.com/questions/5333/logical-operators-or-and-in-condition-and-order-of-conditions-in-where) also – rs. Apr 11 '14 at 18:06

1 Answers1

0

According to this post by Mladen Prajdić, the answer is no, SQL Server does not do short-circuiting for OR conditions:

http://weblogs.sqlteam.com/mladenp/archive/2008/02/25/How-SQL-Server-short-circuits-WHERE-condition-evaluation.aspx

Also, see this post.

If order really matters to you, you can use a CASE WHEN statement. SQL Server always evaluates CASE WHEN conditions in order.

Community
  • 1
  • 1
Paul Williams
  • 16,585
  • 5
  • 47
  • 82