Subject Re: [ib-support] Immediately get auto generated key
Author Arno Brinkman
Hi,

> Is it possible in one Stored Procedure to get the auto generated key
> for a row?

I guess you use an generator in the trigger and check if SESSION_ID IS NULL.

> begin
> INSERT INTO PLANSESSIONS ( SESSION_INFO )
> VALUES ( :SESSIONINFO );
> suspend;
> end
>
> But would like to get directly the autogenerated key 'SESSION_ID'.
> How can I do this?

Generate first the ID in the SP and use that as input value inside your
INSERT.

DECLARE VARIABLE ID INTEGER;
BEGIN
ID = GEN_ID("GEN_SESSION_ID",1);
INSERT INTO
PLANSESSIONS (SESSION_ID, SESSION_INFO )
VALUES (:ID, :SESSIONINFO);
SUSPEND;
END

Regards,
Arno