FIX: SQLNumResultCols Fails with Incorrect Syntax Near 'SET'

Last reviewed: October 29, 1997
Article ID: Q153694
6.50 WINDOWS kbnetwork kbbug6.50 kbfix6.50.sp1

The information in this article applies to:

  • Microsoft Open Database Connectivity, version 2.65

SYMPTOMS

Calling SQLNumResultCols after SQLPrepare of a SELECT statement that contains a subquery in the select list will fail with:

   szSqlState = "37000", pfNativeError = 156
   szErrorMsg="[Microsoft][ODBC SQL Server Driver][SQL Server]
               Incorrect syntax near the keyword 'SET'."

CAUSE

When the SQL Server ODBC driver constructs the T-SQL statement that will be sent to the server to resolve the number of columns that will be returned in the resultset, it incorrectly parses the initial query and excludes the final table name. For example:

   SQLPrepare(hstmt, "SELECT t1.c1, (SELECT t2.c1 FROM t2)
                      FROM t1", 44)
   SQLNumResultCols(hstmt, pcol1)

This results in the following statement being sent to the server on the call to SQLNumResultCols:

   SET FMTONLY ON SELECT t1.c1, (SELECT t2.c1 FROM t2)
   FROM SET FMTONLY OFF

Hence, causing SQL Server to report "Incorrect syntax near the Keyword
'SET'."

WORKAROUND

Where possible convert the offending query to a SQL Server VIEW.

STATUS

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


Additional reference words: 6.50 sp1
KBCategory: kbnetwork kbbug6.50 kbfix6.50.sp1
KBSubcategory:
Keywords : kbbug6.50 kbfix6.50.sp1 kbnetwork
Version : 6.50
Platform : WINDOWS
Solution Type : kbfix


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