Subject RE: [firebird-support] Re: Inserting new rows if an updated row does not exist.
Author Cao
Stored Procedure
BEGIN
INSERT INTO Table(Fields...)
VALUES (:Values..........);
EXIT;
/* Duplicated key error - the record already exists so update the
record*/
WHEN SQLCODE -803 DO
BEGIN
UPDATE Table
set Field=:Value ...
where Key=:Parameter;
EXIT;
END
END

regards cao

-----Original Message-----
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com]On Behalf Of Adam
Sent: 10 May 2007 02:59
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Re: Inserting new rows if an updated row does
not exist.


--- In firebird-support@yahoogroups.com, "ariel.sakin" <asakin@...> wrote:
>
> Hi,
> I am using Firebird 1.5 and I want to create a query that updates a
> row, or creates a new one if the row does not exist.
> I found that in 2.1 there will be a REPLACE/MERGE command for doing
> this, but I was not able to find a solution for 1.5 (Other than
> checking if a row exists in a separate query).
>
> Is there any way of doing this in a more efficient way?

You could use a stored procedure to achieve a similar thing in 1.5,
but merge is definately a better solution when 2.1 is finished.

Adam






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