FIX: SELECT DISTINCT from Table with LEFT JOIN of View Causes Error Messages or Client Application May Stop Responding

This article was previously published under Q308547
This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 355640 (SHILOH_BUGS)
A SELECT DISTINCT query that joins a table to a view through an outer join may:
  • Cause error messages or exceptions at the client.
  • Produce the appearance of incorrect results.
  • Cause the client application to stop responding (hang).
The error messages that may occur include:
Bad token from SQL Server: Datastream processing out of sync.
Unknown token received from SQL Server
Protocol error in TDS stream
Invalid cursor state
Function sequence error
To resolve this problem, obtain the latest service pack for Microsoft SQL Server 2000. For additional information, click the following article number to view the article in theMicrosoft Knowledge Base:
290211 INF: How to Obtain the Latest SQL Server 2000 Service Pack


NOTE: The following hotfix was created prior to Microsoft SQL Server 2000 Service Pack 2.

The English version of this fix should have the following file attributes or later:
   Date           Version    Platform   -----------------------------------   Sqlservr.exe   8.00.452   i386				
NOTE: Due to file dependencies, the most recent hotfix or feature that contains the preceding files may also contain additional files.

To work around this problem either:
  • Remove the DISTINCT keyword from the query, or select from the base table instead of from a view that references the table.


  • Change the nullability of the columns in the base table that are selected by the query (the problem arises when the nullability of column data differs from the metadata reported to the client).
Microsoft has confirmed that this is a problem in Microsoft SQL Server 2000. This problem was first corrected in Microsoft SQL Server 2000 Service Pack 2.
The following script demonstrates the problem:
use mastergodrop database dbtestcreate database dbtest use dbtestgocreate table dbtest (  c1 smallint not null primary key,   c2 char(30) null) create table dbtest2 (  c1 smallint not null,  c2 smallint not null,  c3 char(30) null)insert into dbtest(c1,c2) values (1,'abcd')insert into dbtest(c1,c2) values (2,'abcdef')insert into dbtest(c1,c2) values (3,'acdef')insert into dbtest2(c1,c2,c3) values (1,1,'abcd')gocreate view dbview as select * from dbtest.dbo.dbtestgoselect distinct dbview.c1,dbview.c2 from dbview left join dbtest2 on dbtest2.c1 = dbview.c1go				

Article ID: 308547 - Last Review: 12/06/2015 05:56:30 - Revision: 3.2

Microsoft SQL Server 2000 Standard Edition

  • kbnosurvey kbarchive kbhotfixserver kbqfe kbbug kbfix kbsqlserv2000presp2fix KB308547