FIX: You receive an incorrect result when you run a query that uses the LIKE operator in SQL Server 2005

Extended support for SQL Server 2005 ended on April 12, 2016

If you are still running SQL Server 2005, you will no longer receive security updates and technical support. We recommend upgrading to SQL Server 2014 and Azure SQL Database to achieve breakthrough performance, maintain security and compliance, and optimize your data platform infrastructure. Learn more about the options for upgrading from SQL Server 2005 to a supported version here.

SYMPTOMS
Consider the following scenario. In Microsoft SQL Server 2005, you run a query that uses the LIKE operator. The execution plan of the query uses the GetRangeThroughConvert function. When you run the query, you may receive an incorrect result. For example, the execution plan for this query may resemble the following.
|--Nested Loops(Inner Join, OUTER REFERENCES:([Expr1010], [Expr1011], |[Expr1012])) |--Merge Interval | |--Concatenation | |--Compute Scalar(DEFINE:(([Expr1005],[Expr1006],[Expr1004])=GetRangeThroughConvert(N'P08.89',NULL,(22)))) | | |--Constant Scan | |--Compute Scalar(DEFINE:(([Expr1008],[Expr1009],[Expr1007])=GetRangeThroughConvert(NULL,N'P08.8?',(10)))) | |--Constant Scan |--Index Seek(OBJECT:([TestLikeBug].[dbo].[Projects].[IX_Projects]), SEEK:( [TestLikeBug].[dbo].[Projects].[ProjectNumber] > [Expr1010] AND [TestLikeBug].[dbo].[Projects].[ProjectNumber] < [Expr1011]), WHERE:(CONVERT_IMPLICIT(nvarchar(12),[TestLikeBug].[dbo].[Projects].[ProjectNumber],0) like N'P08.89%') ORDERED FORWARD)
CAUSE
This issue occurs because SQL Server generates an incorrect range condition for the LIKE operator.
RESOLUTION

Service pack information

To resolve this problem, obtain the latest service pack for SQL Server 2005. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
913089 How to obtain the latest service pack for SQL Server 2005
STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section. This problem was first corrected in SQL Server 2005 Service Pack 3.
MORE INFORMATION
For more information about software update terminology, click the following article number to view the article in the Microsoft Knowledge Base:
824684 Description of the standard terminology that is used to describe Microsoft software updates
Properties

Article ID: 959019 - Last Review: 12/16/2008 00:47:58 - Revision: 1.0

Microsoft SQL Server 2005 Standard Edition, Microsoft SQL Server 2005 Developer Edition, Microsoft SQL Server 2005 Enterprise Edition, Microsoft SQL Server 2005 Standard X64 Edition, Microsoft SQL Server 2005 Standard Edition for Itanium-based Systems, Microsoft SQL Server 2005 Enterprise X64 Edition, Microsoft SQL Server 2005 Enterprise Edition for Itanium-based Systems, Microsoft SQL Server 2005 Workgroup Edition

  • kbsql2005engine kbtshoot kbexpertiseadvanced kbfix kbbug KB959019
Feedback