Subject | Re: [firebird-support] Re: Select + Update in a single SPROC? |
---|---|
Author | Woody |
Post date | 2007-11-23T16:39:28Z |
From: "hartertobak" <hartertobak@...>
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)
>thank you for clarifying. I just couldn´t believe that doing thisThen you almost had it right in your original post. Here is how I would
>(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.
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)