Subject Re: [firebird-support] order by
Author Ann Harrison
On Mon, Apr 7, 2014 at 6:47 AM, checkmail <check_mail@...> wrote:

I’ve a litte question. Now I can order by the column number, order by 1. Can I set this information with a variable?

Dim k as integer = 1;

Order by :k?

You can do the equivalent with an EXECUTE STATEMENT.    With the exception of EXECUTE {STATEMENT | BLOCK}, Firebird optimizes a statement the first time it is presented.  Query optimization includes choosing how and when to sort the input.  Optimizing once and executing many times is more efficient than using EXECUTE STATEMENT which treats each new iteration as a totally new statement.

Good luck,


P.S.  I agree with the person who discourage the use of column numbers in order by clauses.  Referencing fields by name rather than position was a huge step forward when going from primitive to relational databases.  I hate to see that abstraction eliminated to save typing.