CREATE CURSOR xx(pk i, pid C(4), lineid C(3), revnum i, origrev i, rectype c(1)) APPEND FROM xx.txt DELIMITED SELECT pk, pid, lineid, revnum, origrev, rectype ; FROM xx WHERE rectype = "A" ; UNION ; SELECT pk, pid, lineid, MAX(revnum) revnum, origrev, rectype ; FROM xx WHERE rectype = "I" AND lineid IN ; (SELECT lineid FROM xx WHERE rectype ="A") ; GROUP BY lineid INTO CURSOR cfini============
>RecordId DocId RevNum >------------------------------------ > 1 0001 3 >>
>RecordId ParentId LineId RevNum OrigRev RecType
>------------------------------------------------------------
> 1 0001 123 1 999 I
> 2 0001 123 2 999 I
> 3 0001 123 3 999 A
> 4 0001 890 1 999 I
> 5 0001 890 2 999 A
>
>
>
>I need to pull all active record (RecType = "A") and the record
>which was active just prior to the currently active record.
>
>So in the example above, if I wanted to see the active line item
>and previous record for line item 123, I would get the line items
>record Id's with 3 and 2.
>
>Any ideas?