FIX: Poor Performance with Inner Join with Multiple LIKE Clauses Using Variables

Article translations Article translations
Article ID: 225093 - View products that this article applies to.
This article was previously published under Q225093
This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 55032 (SQLBUG_70)
Expand all | Collapse all


An inner join between two tables with multiple LIKE clauses produces a poor query plan if the LIKE clauses use variables instead of string literals.


To work around this use one of the following:
  • Replace the variables with string constants.
  • Provide a hint to force a loop join. For example, use an INNER LOOP JOIN instead of an INNER JOIN.
  • Use the system stored procedure sp_executesql to execute the query, passing the variables as parameters. For syntax details see the Books Online article "sp_executesql (T-SQL)".


Microsoft has confirmed this to be a problem in SQL Server 7.0. This problem has been corrected in U.S. Service Pack 2 for Microsoft SQL Server 7.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
254561 INF: How to Obtain Service Pack 2 for Microsoft SQL Server 7.0 and Microsoft Data Engine (MSDE) 1.0
For more information, contact your primary support provider.


The following conditions must be met to encounter this bug:
  1. The query must contain an inner join.
  2. The WHERE clause of the query must contain multiple LIKE predicates.
  3. The LIKE predicates must be passed a variable, not a string constant (that is, "... AND column LIKE @myvar1 ...").
The inner join may use either ANSI-standard or Transact-SQL (TSQL) join syntax.

For example, the following query demonstrates this problem:
SELECT p.first_name
FROM person p
INNER JOIN customer c ON p.person_id = c.person_id 
WHERE p.last_name LIKE @last_name AND
   p.first_name LIKE @first_name 


Article ID: 225093 - Last Review: October 20, 2013 - Revision: 2.1
  • Microsoft SQL Server 7.0 Standard Edition
kbnosurvey kbarchive kbbug kbfix KB225093

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from