Here is an option. To build table B, I have used excel to quickly create the 1 - 99 and copied that with parentheses and commas into Run SQL Scripts
with
tblA (filedA) as (values('P'))
,tblB (fieldB) as (values(1),(2),(3),(4),(5),(6),(7),(8),(9),(10)) /*Keep adding numbers until you get to 99*/
,tblC (fieldC) as (values(1),(2),(3),(4),(5),(6),(7))
,tblD (fieldD) as (values(1),(2),(3),(4),(5),(6),(7))
select * from tblA, tblB, tblC, tblD
-Tom Stieger
IT Manager
California Fine Wire
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Alan Shore
Sent: Wednesday, September 04, 2013 1:28 PM
To: midrange-l@xxxxxxxxxxxx
Subject: Using sql to update a running sequence number on each successive record in a file
Hi guys
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
FieldA 1
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
Etc.
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 avail
Anyway - as always - all answers gratefully accepted
Alan Shore
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,
visit:
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at
http://archive.midrange.com/midrange-l.
As an Amazon Associate we earn from qualifying purchases.