BUG: Cursor Open 533 Error on UNION if MAX or MIN in Subquery

Last reviewed: May 2, 1997
Article ID: Q147674

The information in this article applies to:
  • Microsoft SQL Server, version 6.0
BUG# NT: 13504 (6.00)

SYMPTOMS

Errors can occur when you open a server cursor on a UNION query where the unioned SELECTs contain correlated subqueries which contain MIN() or MAX(). Db-library clients see the following errors:

   DB-Library error 10008: Possible network error: Bad token from SQL
                           Server: Datastream processing out of sync.
   Msg 533, Level 20, State 4
                       Can't find a range table entry for range 4.
   DB-Library Process Dead - Connection Broken

ODBC clients see the following single error if they call SQLError():

   szSqlState = "S1000", *pfNativeError = 0,
   szErrorMsg="[Microsoft][ODBC SQL Server Driver]
               Unknown token received from SQL Server"

The problem happens on all types of server cursors (Dynamic, Keyset, Static, Forward Only).

STATUS

Microsoft has confirmed this to be a problem in the Microsoft SQL Server version 6.00. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

This problem no longer occurs in version 6.50.

WORKAROUND

Do not use a server cursor to process the command. Alternatively, perform the two UNIONed SELECTs into temporary tables and then perform the union between the temporary tables. For example, take:

   select distinct t1.type
   from titles t1
   where t1.type in ( select max(t2.type)
                                  from titles t2
                                  where t1.pub_id != t2.pub_id )
   union
   select distinct t1.type
   from titles t1
   where t1.type in ( select max(t2.type)
                                  from titles t2
                                  where t1.pub_id != t2.pub_id )
and change it to:

   select distinct t1.type into #temp1
   from titles t1
   where t1.type in ( select max(t2.type)
                                  from titles t2
                                  where t1.pub_id != t2.pub_id )
   go
   select distinct t1.type into #temp2
   from titles t1
   where t1.type in ( select max(t2.type)
                                  from titles t2
                                  where t1.pub_id != t2.pub_id )
   go
   select * from #temp1
   union
   select * from #temp2


Additional query words: sql6 cursor tsql
Keywords : kbbug6.00 kbprg SSrvProg SSrvTran_SQL
Version : 6.0
Platform : WINDOWS
Issue type : kberrmsg


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.