Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread How to get the value of a generated identity in a procedure...
Mon, Apr 28 2008 9:55 AMPermanent Link

Uli Becker
I am sure I read it anywhere but cannot find it any more: How can I
return an auto-generated identity value after inserting a record from a
stored procedure?

I remember there is something different from (select max...)

Thanks. Uli
Mon, Apr 28 2008 2:02 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Uli,

<< I am sure I read it anywhere but cannot find it any more: How can I
return an auto-generated identity value after inserting a record from a
stored procedure? >>

To retrieve the new identity column value in the procedure, use something
like this:

PROCEDURE "ReturnIdentity" (OUT "ResultIdentity" INTEGER)
BEGIN
  DECLARE InsertStmt STATEMENT;

  PREPARE InsertStmt FROM 'INSERT INTO Customer (CustNo) VALUES (?)';
  EXECUTE InsertStmt USING ResultIdentity;
END

One note - the EDB Manager currently isn't executing "output-param-only"
procedures due to a bug, but they will work fine in your application.

--
Tim Young
Elevate Software
www.elevatesoft.com

Mon, Apr 28 2008 2:35 PMPermanent Link

Uli Becker
Tim
> To retrieve the new identity column value in the procedure, use something
> like this:
>
> PROCEDURE "ReturnIdentity" (OUT "ResultIdentity" INTEGER)
> BEGIN
>    DECLARE InsertStmt STATEMENT;
>
>    PREPARE InsertStmt FROM 'INSERT INTO Customer (CustNo) VALUES (?)';
>    EXECUTE InsertStmt USING ResultIdentity;
> END

Thank you!

Regards Uli
Image