FIX: Using a WHERE IN Clause on a Selected UNION May Fail

Last reviewed: April 10, 1997
Article ID: Q162366
The information in this article applies to:
  • Microsoft SQL Server, version 6.5 Service Pack 1
BUG #: 16400 (SQL6.5)

SYMPTOMS

SELECT statements consisting of a UNION and a WHERE IN clause may fail.

For example, the following statement

   SELECT type, name
      FROM (SELECT * FROM master..sysobjects
                UNION
                SELECT * FROM pubs..sysobjects) as O
      WHERE type IN ('S', 'U')

Produces (in part) the following results:

  type name
  ---- ------------------------------
  U    authors
  P    byroyalty
  C    CK__authors__au_id__02DC7882
  C    CK__authors__zip__04C4C0F4
  C    CK__jobs__max_lvl__2719D8F8
  C    CK__jobs__min_lvl__2625B4BF
  C    CK__publisher__pub_i__089551D8
  C    CK_emp_id

WORKAROUND

Embed SELECT statements into the WHERE IN clause, as shown by the following:

   SELECT type, name
      FROM (SELECT * FROM master..sysobjects
         UNION
         SELECT * FROM pubs..sysobjects) as O
      WHERE type IN (SELECT 'S' UNION SELECT 'U')

STATUS

Microsoft has confirmed this to be a problem in Microsoft SQL Server version 6.5 Service Pack 1. This problem has been corrected in U.S. Service Pack 2 for Microsoft SQL Server version 6.5. For more information, contact your primary support provider.


Additional query words:
Keywords : kbbug6.50.sp1 kbfix6.50.sp2 kbusage SSrvProg
Version : 6.5 SP1
Platform : WINDOWS


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: April 10, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.