Subject Re: [firebird-support] update First xx record
Author unordained
---------- Original Message -----------
From: "svanderclock" <svanderclock@...>
Subject: [firebird-support] update First xx record
> update first xx tableA set field1=xxx where ...
------- End of Original Message -------

1) Don't forget that "first N" only makes real sense if you also ORDER BY
something. Match by primary key:

update A set F1 = ? where A.primary_key in (select first ? A.primary_key from A
where ... order by A.some_field);

2) If you don't have a primary key field, or it's a multi-column key, you could
use rdb$db_key instead:

update A set F1 = ? where A.rdb$db_key in (select first ? rdb$db_key from A
where ... order by A.some_field);

3) Cursor-based update:

execute block
as
declare variable f_1 some_type;
begin
for select first ? F1 from A where ... order by A.some_field into :f_1 as cursor
STUFF do
begin
update A set F1 = ? where current of STUFF;
end
end

(I provide the last as an "execute block", so you can run it directly from a
client-app without creating a named stored procedure, but I don't know that you
can use "?" prepared statement parameters in the body of a procedure. For that
matter, I don't remember if you can do it for "first ?" clauses, either.)

-Philip