Microsoft KB Archive/294138

= FIX: Outer Join Syntax with Parameter Fails Against SQL Server 6.5 =

Article ID: 294138

Article Last Modified on 9/26/2005

-

APPLIES TO


 * Microsoft Data Access Components 2.1
 * Microsoft Data Access Components 2.5
 * Microsoft Data Access Components 2.6

-



This article was previously published under Q294138



SYMPTOMS
When you use the &quot;oj&quot; outer join syntax with a parameter in a SELECT statement using the Microsoft SQL Server driver with a SQL Server 6.5 back end, the following error message is returned:

&quot;[Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error&quot;



CAUSE
The problem occurs when the driver removes ODBC escape characters from the query.



RESOLUTION
To resolve this problem, obtain the latest service pack for Microsoft Data Access Components 2.6. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

300635 INFO: How to Obtain the Latest MDAC 2.6 Service Pack

Hotfix
The English version of this fix should have the following file attributes or later:

Date      Time    Version           Size    File name      Platform

3/16/2001 2:48AM  2000.80.268.0   28,742    Odbcbcp.dll    x86 3/16/2001 2:48AM  2000.80.268.0  471,119    Sqlsrv32.dll   x86 3/16/2001 2:48AM  2000.80.268.0   90,112    Sqlsrv32.rll   x86



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was first corrected in Microsoft Data Access Components 2.6 Service Pack 1.



Steps to Reproduce Behavior
  Create the following tables on a SQL Server 6.5 back end: create table t1(c1 int, c2 int) create table t2(c1 int, c2 int)   Paste the following code in a Microsoft Visual C++ console application:
 * 1) include 
 * 2) include 
 * 3) include 
 * 4) include 
 * 5) include 
 * 6) include <sqlext.h>

void main(void) {   SQLHANDLE henv; SQLHANDLE hdbc; SQLHANDLE hstmt; RETCODE rc;

char Statement[100] = {&quot;select * from {oj t1 left outer join t2 on t1.c1=t2.c2} where t1.c1=?&quot;}; char dsn[10] = {&quot;YourDSNName&quot;}; char user[5] = {&quot;YourUserName&quot;}; char pass[7] = {&quot;YourPassword&quot;}; int param =1; long sqlnts = SQL_NTS; long m_bytesRet = SQL_NTS; long cbOparm = 0; rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); rc = SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC3, SQL_IS_UINTEGER); rc = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); rc = SQLConnect(hdbc, (SQLCHAR *)dsn, SQL_NTS, (SQLCHAR *) user,SQL_NTS,(SQLCHAR *) pass, SQL_NTS); rc = SQLAllocHandle(SQL_HANDLE_STMT,hdbc,&hstmt); rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG,SQL_INTEGER, 0, 0,&param, 0, &cbOparm); rc = SQLPrepare(hstmt, (SQLCHAR *)Statement, SQL_NTS); rc = SQLExecute(hstmt);

// Variables for SQLDiagRec. char mstate[6] = &quot;\0&quot;; long native = 0; char mtext[300] = &quot;\0&quot;; short mlength = 0; short i = 0;

while ((rc = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, ++i, (unsigned char*)&mstate, &native, (unsigned char*)&mtext,300,&mlength))!=SQL_NO_DATA) printf(&quot;\nODBC Error:\t%s\n&quot;,mtext); }                   </li> Change the data source name, user id, and password.</li> Compile and then run the code.</li></ol>

Keywords: kbbug kbfix kbqfe kbmdac260sp1fix kbhotfixserver KB294138

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.