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

Article translations Article translations
Article ID: 308547 - View products that this article applies to.
This article was previously published under Q308547
BUG #: 355640 (SHILOH_BUGS)
Expand all | Collapse all

On This Page


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 the Microsoft 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 master
drop database dbtest
create database dbtest 
use dbtest
create 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')
create view dbview as select * from dbtest.dbo.dbtest
select distinct dbview.c1,dbview.c2 from dbview 
left join dbtest2 on dbtest2.c1 = dbview.c1


Article ID: 308547 - Last Review: September 26, 2005 - Revision: 3.2
  • Microsoft SQL Server 2000 Standard Edition
kbhotfixserver kbqfe kbbug kbfix kbsqlserv2000presp2fix KB308547

Give Feedback


Contact us for more help

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