SQL Server - Query Short-Circuiting?

Posted by Sam Schutte on Stack Overflow See other posts from Stack Overflow or by Sam Schutte
Published on 2008-12-19T15:09:43Z Indexed on 2010/04/27 12:13 UTC
Read the original article Hit count: 324

Filed under:
|
|

Do T-SQL queries in SQL Server support short-circuiting?

For instance, I have a situation where I have two database and I'm comparing data between the two tables to match and copy some info across. In one table, the "ID" field will always have leading zeros (such as "000000001234"), and in the other table, the ID field may or may not have leading zeros (might be "000000001234" or "1234").

So my query to match the two is something like: select * from table1 where table1.ID LIKE '%1234'

To speed things up, I'm thinking of adding an OR before the like that just says: table1.ID = table2.ID to handle the case where both ID's have the padded zeros and are equal.

Will doing so speed up the query by matching items on the "=" and not evaluating the LIKE for every single row (will it short circuit and skip the LIKE)?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server