I am trying to get data from MS Access database. But my query with LIKE operator
doesn't work. i am using DSN less connection using DAO SDK.
My database table is like this:
EMPID age_category
(number) (text)

1 056478
2 158769
3 025796
4 185246


my query is: select empid from EmpDetails where age_category like '0[1-6]*'

it doesn't work. it returns 0 rows.

please see my code:


#include <iostream>
#include <rpc.h>
#include <sql.h>
#include <sqlext.h>

using namespace std;
#define MAXBUFLEN 255

int main()
{
SQLHENV henv = SQL_NULL_HENV;
SQLHDBC hdbc = SQL_NULL_HDBC;
SQLHSTMT hstmt= SQL_NULL_HSTMT;
RETCODE retcode;
SQLCHAR ConnStrIn[MAXBUFLEN] = "DRIVER={Microsoft Access
Driver (*.mdb)};
Dbq=c:\\MyDB.mdb";
SQLCHAR ConnStrOut[MAXBUFLEN];
SQLSMALLINT cbConnStrOut = 0;
SQLINTEGER nEMPID, cbEMPID;

retcode = SQLAllocEnv(&henv);
retcode = SQLAllocConnect(henv, &hdbc);

retcode = SQLDriverConnect(hdbc,NULL,ConnStrIn,SQL_NTS,
ConnStrOut,MAXBUFLEN,
&cbConnStrOut,SQL_DRIVER_NOPROMPT);
if( retcode != SQL_SUCCESS)
return 1;

std::string strQuery="select empid from EmpDetails
where age_category like '0[1-6]*'";

retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
if( retcode != SQL_SUCCESS)
return 2;

retcode = SQLExecDirect(hstmt,(SQLTCHAR *)
strQuery.c_str(), SQL_NTS);
if(( retcode != SQL_SUCCESS) &&
( retcode != SQL_SUCCESS_WITH_INFO))
return 3;

retcode = SQLBindCol(hstmt, 1, SQL_C_LONG, &nEMPID, 0, &cbEMPID);
if(retcode == SQL_ERROR)
return 4;


while ( SQLFetch(hstmt) != SQL_NO_DATA_FOUND)
{
cout << nEMPID << endl;
}

return 0;
}


please correct me.

regards,
Sri Ram