Skip to Content
0
Former Member
Apr 30, 2013 at 04:56 AM

"select top ?" query from ODBC fails with Incorrect syntax

573 Views

Dear Friends,

I am enhancing a C++ application on Windows 7 to connect to Sybase ASE 15.7 (64bit) database using ODBC driver.

For fetching a limited number of rows, I want to use "top n" syntax.

To utilize prepared statements, I am using parameter marker "?" for "top ?", where "?" will indicate the number of rows to be selected.

Calls to SQLPrepare and SQLBindParameter are successful. But, SQLExecute fails with the following error:

[Sybase][ODBC Driver][Adaptive Server Enterprise]Incorrect syntax near '@dr_ta0'., sqlstate:42000

Query being prepared and executed is as below:

"select top ? charpk,ccno,anumber,updateddate from myccinfo.dbo.charpktable NOLOCK order by charpk asc ;"

SQLBindParameter is called as below:

unsigned int m_rowsToGet = 100;

SQL_RETURN ret = SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG,

SQL_INTEGER, 0, 0, &m_rowsToGet, 0, );

Does Sybase ASE ODBC driver support parameter marker for "top n" command?

What could be wrong here? This same query works fine with MS-SQL ODBC driver.

Sorry if this is not the correct forum for this question. Can you please help to migrate my question to the correct forum?

Many thanks in advance for your help and time.

Best Regards.