Subject RE: [firebird-support] how to use order by for selected record in insert
Author Mercea Paul
I have changed the fields and I can run a simple select like:

Select c2.ord, c2.complete_descr

From rpr_comp ce

Where c2.code=:oldid

Order by c2.ord

This statement is valid, but if I want to insert this select I get
error.probably because that order can't be assigned to the select statement.



But I can't use :

Insert into rpr_comp (:newid, ord, complete_descr)

Select c2.ord, c2.complete_descr

From rpr_comp ce

Where c2.code=:oldid

Order by c2.ord





The error I get is 'Parsing error!' ! Using IBExpert !



I think the only way to insert in some order is to use variables and : for
select x,y,z from table order by 2 do begin insert x,y,z end!



Regards,

Paul





From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of Uwe Grauer
Sent: Sunday, February 10, 2008 7:48 PM
To: firebird-support@yahoogroups.com
Subject: Re: [firebird-support] how to use order by for selected record in
insert



Mercea Paul wrote:
> Hi
>
> 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!
>
> How can I insert ? (without using variables)
>
> TIA,
> Paul

It would help to see the compilation error you are getting.
I think "order" is a reserved word in Firebird.

Uwe





[Non-text portions of this message have been removed]