× 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.



On 14 Jun 2013 05:34, Charles Wilt wrote:
Never use dynamic unless you have too :)

<<SNIP>>

Off the top of my head, the only place you have to use a dynamic
statement is when you need the table name to be variable. You also
can't use a parameter here:

stmt = 'select * from ' + tableName + ' where myfld = 1';


Even that does not meet the criteria for "have to use a dynamic statement". Using an override with static SQL would be a better choice IMO. Even an effectively dynamic ALIAS would suffice [albeit I always suggest against such /temporary/ use of an ALIAS, even if created in QTEMP] in place of an override.

Before running the static SQL, assign the /variable/ table-reference; i.e. where the value of "MYTABLE" comes from whatever actual or effective variable:

OVRDBF OVERRIDDEN TOFILE(*LIBL/MYTABLE) OVRSCOPE(as_required)

*or*

CREATE OR REPLACE ALIAS OVERRIDDEN ON MYTABLE /* naming=*SYS */

Then the static SQL referencing the label OVERRIDDEN as the table-reference:

exec SQL
select * into :myDS from OVERRIDDEN where myfld = :myVar ;

Ideally the program would get compiled with the override in effect or the ALIAS existing in the appropriate library [within the library list], to enable the Access Plan for the statement to be created then [if possible], as opposed to the creation being delayed until when the program is first run.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.