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



You could construct up the entire select command into one variable then prepare, declare, open and read the result set

This is older embedded SQL but should give the you idea. SelVar is a SELECT... FROM .... WHERE..... which in this app we needed to vary the where clause. File and fields returned were static but it should work with static where and variable file

C/EXEC SQL PREPARE P1 FROM :SelVar
C/END-EXEC
C/EXEC SQL DECLARE StudNames CURSOR FOR P1
C/END-EXEC
C/EXEC SQL OPEN StudNames
C/END-EXEC
C/EXEC SQL WHENEVER NOT FOUND GO TO EOF
C/END-EXEC

C DOW SQLSTT = '00000'

C/EXEC SQL FETCH StudNames INTO :Lname, :Fname, :Mname, :Ssid1, :
C+ :Ssid3, :City, :State
C/END-EXEC


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Jerry Adams
Sent: Friday, March 07, 2008 12:29 PM
To: RPG Midrange
Subject: FROM Technique?

I'm trying to use the following embedded SQL in an RPG IV program:

EXEC SQL
select count(*) into :count from :table
where dlitm# = :item# and dldate >= :lastWeek;

I was trying to use "from :table" because our History tables get pushed
at year-end close into a new library, such as HIST2007. Next year at
this time, the library will be named HIST2008 so I wanted to be "flexible".

I tried using a PREPARE and dynamic SQL, but it didn't like the INTO clause.

The manuals and Redbooks don't say that the FROM clause can't take a
variable, but they come awfully close (semantics). But I thought that,
if anyone has figured out a way to circumvent the rules, it would be
someone on the list. Hopefully, when I get back on Monday morning,
someone (or more) of you will have shown me the error of my ways so that
I don't have to do USROPN's with EXTFILE( ) and actually read the table.

Thanks.
--
* Jerry C. Adams
*IBM System i Programmer/Analyst
B&W Wholesale Distributors, Inc.* *
voice
615.995.7024
fax
615.995.1201
email
jerry@xxxxxxxxxxxxxxx <mailto:jerry@xxxxxxxxxxxxxxx>


--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.


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.