Help and Support

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

Article ID:308547
Last Review:September 26, 2005
Revision:3.1
This article was previously published under Q308547
BUG #: 355640 (SHILOH_BUGS)
On This Page

SYMPTOMS

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.
-or-
Unknown token received from SQL Server
-or-
Protocol error in TDS stream
-or-
Invalid cursor state
-or-
Function sequence error

Back to the top

RESOLUTION

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 (http://support.microsoft.com/kb/290211/EN-US/) INF: How to Obtain the Latest SQL Server 2000 Service Pack

Back to the top

Hotfix

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.


Back to the top

WORKAROUND

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.

-or-

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).

Back to the top

STATUS

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.

Back to the top

MORE INFORMATION

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

Back to the top


APPLIES TO
Microsoft SQL Server 2000 Standard Edition

Back to the top

Keywords: 
kbbug kbfix kbqfe kbsqlserv2000presp2fix kbhotfixserver KB308547

Back to the top

Article Translations

 

Related Support Centers

Other Support Options

  • Contact Microsoft
    Phone Numbers, Support Options and Pricing, Online Help, and more.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.