× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Rob,

stmt='Select cmpny, cmpnam, cmpost ' +
'from rco ' +
'where cmpny between :lowCmpny and :highCmpny ' +
'and cmpnam between :lowCmpnam and :highCmpnam ' +
'and cmpost between :lowCmpost and :highCmpost ' +
'order by ?';

No, this isn't valid. Since you are building the SQL statement on-the-fly, you can't use :lowCmpny or any other variable that starts with a colon. That code is normally handled at compile-time by the SQL precompiler -- and nothing handled at compile-time will work in this case, because you're building the SQL statement using string concatenation at run-time. You could, however, replace those with parameter markers (question marks) and fill them in that way.

You also can't use a parameter marker (the question mark) for "order by". Parameter markers can only replace variable/column values. they can't replace code that's used to develop the query plan.

in any case, your statement is a bad example of dynamic SQL because it could be done (actually easier) as a static statement. (Notice how I handle the order by:)

exec SQL declare C1 cursor for
Select cmpny, cmpnam, cmpost
from rco
where cmpny between :lowCmpny and :highCmpny
and cmpnam between :lowCmpnam and :highCmpnam
and cmpost between :lowCmpost and :highCmpost
order by case
when :sortby = '1' then cmpny
when :sortby = '2' then cmpnam
when :sortby = '3' then cmpost
end

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.