Subject | Select + Update in a single SPROC? |
---|---|
Author | hartertobak |
Post date | 2007-11-23T08:20:29Z |
Hi there,
I´m just starting with firebird and wondering how to achieve the
following:
I´m doing a select to find out if a record for a given parameter
exists. If not, I´d like to insert a new record, else I´d like to
update one field of the existing record (which is an integer -> this
integer needs an increment +1).
I do have some code (SPROC) but I don´t get it working. Please
hint me something:
ALTER PROCEDURE SP_TBLINDEX_INS_UPD
(
SEARCHTERM VARCHAR(400) CHARACTER SET UTF8 DEFAULT NULL
)
RETURNS
(
SEARCHEXISTS SMALLINT
)
AS
BEGIN
select ID from TBLONE where searchterm = :SEARCHTERM into :SEARCHEXISTS;
SUSPEND;
if (:SEARCHEXISTS = 0) THEN
insert into TBLONE (SEARCHTERM, LASTSEARCH, SEARCHCOUNT) VALUES
(:SEARCHTERM,cast('now' as timestamp), 1);
END
The update-thing for an existing record is missing, but even the
insert-part does not work. Any help is greatly appreciated :)
I´m just starting with firebird and wondering how to achieve the
following:
I´m doing a select to find out if a record for a given parameter
exists. If not, I´d like to insert a new record, else I´d like to
update one field of the existing record (which is an integer -> this
integer needs an increment +1).
I do have some code (SPROC) but I don´t get it working. Please
hint me something:
ALTER PROCEDURE SP_TBLINDEX_INS_UPD
(
SEARCHTERM VARCHAR(400) CHARACTER SET UTF8 DEFAULT NULL
)
RETURNS
(
SEARCHEXISTS SMALLINT
)
AS
BEGIN
select ID from TBLONE where searchterm = :SEARCHTERM into :SEARCHEXISTS;
SUSPEND;
if (:SEARCHEXISTS = 0) THEN
insert into TBLONE (SEARCHTERM, LASTSEARCH, SEARCHCOUNT) VALUES
(:SEARCHTERM,cast('now' as timestamp), 1);
END
The update-thing for an existing record is missing, but even the
insert-part does not work. Any help is greatly appreciated :)