Subject Re: [firebird-support] Help with FireBird SQL...
Author Aage Johansen
On Tue, 5 Aug 2003 18:34:13 +0000 (UTC), Klerman Gutierrez wrote:

> I'm trying to write an stored procedure that should update the records of
> the main database, with the contents of a temporal database. The query
> should be written as:
>
> UPDATE states set state_name = tmpStates.state_name FROM states INNER
> JOIN
> tmpStates ON state.state_code = tmpStates.state_code;
>
> It doesn't work at all.
> I really can figure out several ways to write the sql to achieve the results
> desired, but I'd like to know the optimal solution for this query in
FireBird.


I think you will have to use something like:
update STATES S
set STATE_NAME = (select STATE_NAME
from TMPSTATES T
where T.STATE_CODE = S.STATE_CODE)

However, this may be inefficient - depends on your Firebird version.
If the plan looks bad (too many NATURALs), you should use a Stored
Procedure (use rdb$db_key feature!). I think the latest FB versions handle
this just fine.

--
Aage J.