In Microsoft SQL Server 2005, you create a table that contains a column of the varchar(max) data type.
You insert a value that only has one character into the column.
You run a query against the table. The query returns the one character value.
The execution plan of the query uses a Hash Match operator.
In this scenario, when you run the query, the query may not return the one character value in the result.
This issue occurs because the implementation of the Hash Match operator does not handle the single-character scenario correctly for the varchar(max) data type.
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
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.
Steps to reproduce the issue
Start SQL Server Management Studio, and then create a new query.
Run the following statements to create tables for a test.
create table #test1 (symbol varchar(64) not null)create table #test2 (symbol varchar(max) not null, id int not null)insert into #test1 values ('A')insert into #test1 values ('AB')insert into #test2 values ('A', 0)insert into #test2 values ('AB', 1)
Run the following statements. You receive a correct result.
select t0.symbol, t1.idfrom #test1 as t0inner loop join #test2 as t1on t0.symbol = t1.symbol collate Latin1_General_BIN
Run the following statements. You receive an incorrect result.
select t0.symbol, t1.idfrom #test1 as t0inner hash join #test2 as t1on t0.symbol = t1.symbol collate Latin1_General_BIN
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