On Sun, 18 Mar 2012 22:26:11 +0200, Newbie <[email protected]> wrote: > How to best implement ORDER BY of a query when the field by which to > order, is given as stored procedure input parameter? > for example a typical product list where could be ordered by Name, Price
> etc fields depending on what user clicks. > > I tried to include it into query: > > for > select f1, f2 from t1 > order by :order_by_field > into :p1, :p2 > > I am not getting any errors, but it doesn't order the list. how to do it > better? > thanks. You can't. You don't get an error as you are now simply ordering by the value of :order_by_field, which is the same for all records. You might get away with using a selector variable to select the field: ORDER BY CASE :selector WHEN 1 THEN field1 WHEN 2 THEN field2 ELSE field3 END If this works I am not sure if it will perform well though. Mark
