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



Denis has it. I'll fix up the syntax a bit and add a join to bring the
data together with MFLD columns for the main columns, and ATR columns for
the attribute columns. You could also use a subselect if you're only
bringing in one column from the main table. I didn't test any of this...

select a.ATR1, a.ATR2,b.MFLD1, b.MFLD2
from FileX a
where a.RcdTyp='ATTRIBUTE'
left outer join lateral
(select MFLD1, MFLD2
from FileX b
where RRN(b)<RRN(a)
and RcdTyp='MAIN'
order by RRN(B)
fetch first row only) B
on 1=1

Alternative as subselect:
select a.ATR1, a.ATR2,
(select MFLD1 from FileX b
where RRN(b)<RRN(a)
and RcdTyp='MAIN'
order by RRN(b)
fetch first row only)
from FileX a
where a.RcdTyp='ATTRIBUTE'




From: Denis Robitaille <denis_robitaille@xxxxxxxxxxxx>
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>
Date: 05/18/2016 09:48 AM
Subject: RE: SQL statement to read previous records
Sent by: "MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxx>



There is a way to get the RRN (relative record number) of the attribute
record
SELECT field1, field2, RRN(myfile)
FROM myfile
WHERE .....

You now have the RRN of the attribute record

Next you can fetch the previous record(s) that is a main record

SELECT field1, Field2
FROM myfile
WHERE type='main record test' and RRN(myfile) < :RRN_attribute_record
ORDER desc BY RRN(myfile)
Select first row only

I am not sure of the syntax but you should get the idea

PS Better be sure of 2 things: The file is configured not to reuse deleted
records. You never do a reorg of the file

Hope this help

Denis Robitaille
Chef de service TI - Solution Entreprise
Infrastructure et Opérations
Cascades Centre des technologies,
412 Marie Victorin
Kingsey falls(Québec) Canada J0A 1B0
T : 819 363 6130



-----Message d'origine-----
De : MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] De la part de Bill
Howie
Envoyé : 18 mai 2016 08:52
À : midrange-l@xxxxxxxxxxxx
Objet : SQL statement to read previous records

Hello all,

I'm working on a project that requires the use of SQL. What I have is a
situation where there can be a group of records in a file where the first
record in a "set" of records is the "main" record and the subsequent
records describe attributes of that "main" record. There is a record type
field in this file which is used to differentiate between the main record
and the "attribute" records. So what I'll have in the file is a "main"
record, then a bunch of "attribute" records, then another "main", then
"attributes", and so on.

There is no field in the "attribute" record that links it back to the
"main" record it goes with. The association between the two is simply the
fact that the "attribute" record comes after the "main" record in the file.
Any thoughts from anyone on an ingenious way to use SQL to grab the
"main" record? I think there has to be a way, just not coming up with it
right now. Any help is appreciated! Thanks!

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

Please contact support@xxxxxxxxxxxx for any subscription related questions.
--
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.

Please contact support@xxxxxxxxxxxx for any subscription related questions.




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.