Subject Re: [IBO] IB_Query Ordering Problems
Author Paul Vinkenoog
Hi Kenneth,

> Hmmm.., I saw this before on other thread. Does it have to
> use at OnPrepareSQL event? Or It can be used at any place and
> refresh the dataset automatically?

You can use SQLOrder any place (unlike SQLWhereItems, which is
only valid in an OnPrepareSQL handler). But it doesn't refresh
the dataset automatically. On an open dataset, do:

with qryItem do
begin
SQLOrder.Text := 'order by LOC_SHOP, ITEMCODE';
InvalidateSQL;
Refresh;
end;

> In the GSG example, it also use SQLWhereItems before
> SQLOrder. So it makes me wonders whether SQLOrder can only
> be used with SQLWhereItems. I am getting confuse.

They are different things. Of course you can set them both in
the same procedure (but again: SQLWhereItems is only valid in
OnPrepareSQL), but you don't have to.

I still think however that if your query has a couple of fixed
orderings, the easiest way is to define them at design time
(using the Query Editor or by assigning OrderingItems via
the Object Inspector), and setting OrderingItemNo at runtime
to switch between orderings. I'm not near my development
computer now, but IIRC setting OrderingItemNo at runtime does
it all, i.e. you don't have to call InvalidateSQL and Refresh -
it's all done for you.


Greetings,
Paul Vinkenoog