FIX: Linked Server Query with Hyphen in LIKE Clause May Run Slower than Expected

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

SYMPTOMS

A query that has a LIKE clause, which contains a hyphen character "-", may run slower than expected against a non-SQL Server linked server for a remote table with a large number of rows.

CAUSE

You can use the hyphen character "-" as a pattern match character for ranges in SQL Server (such as [a-z]), but it is not an ANSI SQL standard pattern matching character. SQL Server incorrectly flags the hyphen character "-" as a non-ANSI pattern matching character instead of a literal hyphen ("-") and therefore prevents the criteria from being sent to the remote provider.

WORKAROUND

If the linked server provider supports it, use the OPENQUERY rowset function to force the entire query to be passed to the remote server.

STATUS

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

MORE INFORMATION

In this situation, the LIKE clause criteria is applied at the local SQL Server server after retrieving all rows from the remote table. So, a query like this:
select * from myremoteserver.mycatalog.myschema.mytable where col1 LIKE 'MS-'
				
is processed as follows:

  1. All rows from mytable are retrieved from the linked server to the local SQL Server server.
  2. The local SQL Server server then applies the LIKE clause criteria to produce the final result. Optimally, the remote source should handle applying the criteria so that less rows are returned to the local SQL Server server.

Properties

Article ID: 275536 - Last Review: October 21, 2013 - Revision: 2.0
APPLIES TO
  • Microsoft SQL Server 7.0 Standard Edition
Keywords: 
kbnosurvey kbarchive kbbug kbfix kbqfe KB275536

Contact us for more help

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