General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
>Can anyone think of a simple way to grab a value from a field in the record immediately before and after the current record, without changing the current record? It has to respect the sort order as well.
>
>It seems like it should be simple, but it's just not coming to me...
>
>Thanks,
>
>Michelle
You probably don't need it now, and it might even be slower, but you can do it with SQL using an "offset" self-join. It is something like:
SELECT stuff FROM yourtable INTO CURSOR step1 NOFILTER ORDER BY whatever
SELECT *, RECNO() AS counter FROM step1 INTO CURSOR step2 NOFILTER ORDER BY counter
SELECT step2A.stuff, step2B.something, somefunction(step2A.whatnot,step2B.whatnot,step2C.whatnot) AS importantresult FROM step2 AS step2A INNER JOIN step2 AS step2B ON step2A.counter = step2B.counter - 1 INNER JOIN step2 AS step2C ON step2B.counter = step2C.counter - 1 ORDER BY step2B.counter.
You may have to reverse signs, or something.
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only