Thanks for that tip Charles. Also looking at those Google search results, there is this quick CTE for the 1 - 99 table without having to create a permanent object:
,tblB (fieldB) as (
SELECT fieldB+1 as fieldB
WHERE fieldB < 100
California Fine Wire
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Charles Wilt
Sent: Wednesday, September 04, 2013 1:53 PM
To: Midrange Systems Technical Discussion
Subject: Re: Using sql to update a running sequence number on each successive record in a file
Google SQL and "numbers table"
select 'P', b.num, c.num, d.num
from numtbl B, numtbl C, numtbl D
where b.num between 1 and 99
and c.num between 1 and 7
and d.num between 1 and 7
Not sure what to make of "only insert the record, if the record is not already there". With what you've told us, there's no reason to go to the
additional trouble. It's easier to simply generate the whole table.
Assuming there's more to it, I'd generate the whole thing above, then update the new table with data from the existing. If you are on 7.1, you could take advantage of the MERGE statement.
On Wed, Sep 4, 2013 at 4:28 PM, Alan Shore <ashore@xxxxxxxx> wrote:
First of all apologies for the subject line.
I'm not too sure if it explains what I am looking for.
Anyway - before I forget - we are on V5r4
What I need to do is add records to a particular file.
The file record is pretty simple
FieldB 2 0
FieldC 1 0
FieldD 3 0
FieldA will be a constant value P
FieldB values 1 thru 99 inclusive
FieldC values 1 thru 7 inclusive
FieldD values 1 thru 7 inclusive
The new records need to be as the following
FieldA FieldB FieldC FieldD
P 1 1 1
P 1 1 2
P 1 1 3
P 1 1 4
P 1 1 5
P 1 1 6
P 1 1 7
P 1 2 1
P 1 2 2
FieldC will eventually max out at 7, changing to 1 with the next
record while FieldB will go to 2 Hopefully, this makes sense - but the
question becomes - is this possible to do in SQL?
Then as if that's not hard enough, only insert the record, if the
record is not already there.
I probably will have to do this in RPGILE, but I was just wondering if
it could be done in SQL I tried googling count and sequence to no
Anyway - as always - all answers gratefully accepted
E-mail : ASHORE@xxxxxxxx
Phone [O] : (631) 200-5019
Phone [C] : (631) 880-8640
Disclaimer: This message contains confidential information and is
intended only for the individual named. If you are not the named
addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by e-mail if you have received
this e-mail by mistake and delete this e-mail from your system. E-mail
transmission cannot be guaranteed to be secure or error-free as
information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses.
The sender therefore does not accept liability for any errors or
omissions in the contents of this message, which arise as a result of
e-mail transmission. If verification is required please request a
hard-copy version. Any views or opinions presented are solely those of
the author and do not necessarily represent those of the company.
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take
a moment to review the archives at
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l