Subject Re: [firebird-support] order by using parameter of stored procedure
Author Helen Borrie
At 09:26 AM 19/03/2012, Newbie wrote:
>How to best implement ORDER BY of a query when the field by which to
>order, is given as stored procedure input parameter?

It is not possible to that directly, as ORDER BY is a structural element that is pre-compiled.

>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:
>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

Use EXECUTE STATEMENT. Look up the Language Reference Update document for your version of Firebird to see how this is achieved. You should find it in the ../doc/ subdirectory of your installation; if not, you can download it from the Firebird website documentation area.