Subject Re: Immediately get auto generated key
Author zifnabbe <zifnabbe@users.sourceforge.net>
Thanks for your reply,

But I want to return the ID as output from stored procedure so that I
can use it further in my program. How can I put the ID as output? Is
the following correct?

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

Thanks,
Tom.

--- In ib-support@yahoogroups.com, "Arno Brinkman" <firebird@a...>
wrote:
> 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