Subject Re: subselect in subselect problem?
Author johnsparrowuk
Try this as an example:

/****************/

create table demo (id integer not null, something varchar(30), prev
varchar(30));
insert into demo values (1,'a',null);
insert into demo values (2,'b',null);
insert into demo values (3,'c',null);
insert into demo values (4,'d',null);


set term !! ;
create or alter procedure doesntwork as
declare variable id integer;
declare variable something varchar(30);
begin
for select id,something from demo into :id, :something do
begin
update demo set prev = (select something from demo where id =
(select max(id) from demo where id < :id))
where id = :id;
end
end!!
set term ; !!

set term !! ;
create or alter procedure doeswork as
declare variable id integer;
declare variable something varchar(30);
declare variable i integer;
begin
for select id,something from demo into :id, :something do
begin
select max(id) from demo where id < :id into :i;
update demo set prev = (select something from demo where id
= :i)
where id = :id;
end
end!!
set term ; !!

/****************/

Thanks,

John