Subject Re: [firebird-support] Re: Select + Update in a single SPROC?
Author Woody
From: "hartertobak" <hartertobak@...>
>thank you for clarifying. I just couldn´t believe that doing this
>(quite) simple task leads in that huge sprocs - that really wouldn´t
>be practicable for each and everyone who uses firebird.
>
>So your description is exactly what I´m trying to do.

Then you almost had it right in your original post. Here is how I would
change it:

ALTER PROCEDURE SP_TBLINDEX_INS_UPD
(
SEARCHTERM VARCHAR(400) CHARACTER SET UTF8)
RETURNS
(
SEARCHCOUNT INT
)
AS
DECLARE VARIABLE SrchID INT;
BEGIN
SrchID = 0;
SEARCHCOUNT = 1;
select ID, SEARCHCOUNT from TBLONE
where searchterm = :SEARCHTERM into :SrchID,
:SEARCHCOUNT;
if (SrchID = 0) THEN BEGIN
insert into TBLONE (SEARCHTERM, LASTSEARCH,
SEARCHCOUNT) VALUES
(:SEARCHTERM, cast('now' as timestamp), 1);
END ELSE BEGIN
SEARCHCOUNT = SEARCHCOUNT + 1;
update TBLONE set SEARCHCOUNT = :SEARCHCOUNT
where ID = :SrchID;
END
SUSPEND;
END

HTH
Woody (TMW)