Subject Re: [firebird-support] how to use order by for selected record in insert
Author Ann W. Harrison
Mercea Paul wrote:
>
> Using FB1.5 I need to copy records from one ID to another in same order
> I have a procedure for copy that contains :
> insert into rpr_com (code, order, complete_descr)
> select :newid, c2.order, c2. complete_descr
> from rpr_comp c2
> where c2. code=:oldid;
>
> I need to order the select by second column (order) ,something like:
> insert into rpr_com (code, order, complete_descr)
> select :newid, c2.order, c2. complete_descr
> from rpr_comp c2
> where c2. code=:oldid order by c2.order;
>
> but I get compilation error when I save the procedure!

That error is correct. The select expression in the subquery does not
include an order by clause. The order by clause is a part of a select
statement, according to the SQL standard, but not a select expression.

The way to get the result you want is to use a stored procedure of
the form

FOR SELECT <whatever> INTO <list>
DO
INSERT <whatever>



Good luck,


Ann