Subject [IBO] Most efficient way to fetch next alphabetical row
Author G. Nau
Am 11 Feb 2005 um 8:53 hat Robert martin geschrieben:
>
> Hi
>
> I might be off track but I suspect the following would do the trick
>
> SELECT FIRST 1 fullname FROM mnames WHERE fullname>'SMITH,JOHN' ORDER BY
> fname;
>
> SELECT FIRST 1 fullname FROM mnames WHERE fullname<'SMITH,JOHN' ORDER BY
> fname
> DESC;
>
>
Robert, that's right, but you'll miss records if you run into identical
names! So it's necessary to concatenate the order and where part
with a primary key, if the used column is NOT UNIQUE.

I use this selects (REF is the primary key here):

next record:
select first(1) * from customer where ((name>:P1) or (name=:P1 and
ref>:P2)) order by name, ref

previous record:
select first(1) * from customer where ((name<:P1) or (name=:P1 and
ref<:P2)) order by name desc, ref desc

Params: P1 is the actual name, P2 is the actual PK

It would be really cool if IBObjects would offer such single row
operations in native mode (not for mass record operations, but for
getting and displaying only a single record).

Regards
Gunther