How to use OdbcParameter in a select query to get the top x

Posted by Admin on 27-Sep-2013 07:31

Hi,

Am trying to select the top x customer records using OdbcParameters. The query am trying to execute is similar to the below.

select top ? c."cust-code", c."cust-name" from pub.cust where cust.primaryId = ?

When i execute this query, i get the following error .. I even tried setting the DbType property as int for the first paramater( top x) and DbType as String for the second parameter (cust.primaryId), but still getting the same error.

ERROR [HY000] [DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Syntax error in SQL statement at or about "? c."cust-code" ,c."cust-na" (10713)

Any suggestions to solve this..

Thanks in advance..

All Replies

Posted by Brody on 15-Oct-2013 12:14

If you have access to the C/C++ code you could use the ODBC API and call SQLSetStmtAttr(SQL_ATTR_MAX_ROWS) on the statement prior to executing.

You may be able to write a stored procedure where you can pass a parameter into the stored procedure to make the top clause parameterized.

Posted by steve pittman on 15-Oct-2013 14:09

OE sql does not support use of a parameter as the TOP value. The TOP value has to be a literal constant.

One workaround would be to dynamically construct the query at runtime, when the actual TOP value you need becomes known.

This thread is closed