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

This article was previously published under Q294138
This article has been archived. It is offered "as is" and will no longer be updated.
When you use the "oj" 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:
"[Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error"
The problem occurs when the driver removes ODBC escape characters from the query.
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 theMicrosoft Knowledge Base:
300635 INFO: How to Obtain the Latest MDAC 2.6 Service Pack


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    x863/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				

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

  1. 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)					
  2. Paste the following code in a Microsoft Visual C++ console application:
    #include <windows.h>#include <stdio.h>#include <stdlib.h>#include <stdio.h>#include <sql.h>#include <sqlext.h>void main(void){   	SQLHANDLE henv;   	SQLHANDLE hdbc;   	SQLHANDLE hstmt;   	RETCODE rc;   	char Statement[100] = {"select * from {oj t1 left outer join t2 on t1.c1=t2.c2} where t1.c1=?"};   	char dsn[10] = {"YourDSNName"};   	char user[5] = {"YourUserName"};   	char pass[7] = {"YourPassword"};	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] = "\0";    long native = 0;    char mtext[300] = "\0";    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("\nODBC Error:\t%s\n",mtext);}					
  3. Change the data source name, user id, and password.
  4. Compile and then run the code.

Article ID: 294138 - Last Review: 02/28/2014 04:26:57 - Revision: 3.2

Microsoft Data Access Components 2.1, Microsoft Data Access Components 2.5, Microsoft Data Access Components 2.6

  • kbnosurvey kbarchive kbhotfixserver kbqfe kbbug kbfix kbmdac260sp1fix kbqfe KB294138