Subject Re: [firebird-support] Stored procedure to return primary key after insert
Author Martijn Tonies
> I'm using a stored proc to insert into a table and return the
> generated primary key, but always says column not found, I doubt the
> problem is in the insert statement... here is a copy of the stored proc:
> CREATE PROCEDURE PRCDR_INSERT_MEMBER (
> CODE_MEM VARCHAR(15),
> FN VARCHAR(25),
> SN VARCHAR(10),
> FL VARCHAR(10),
> SLN VARCHAR(10))
> RETURNS (
> ID_MEM INTEGER)
> AS
> begin
> id_mem = gen_id( GEN_ID_MEMBER, 1 );
> CODE_MEM = CODE_MEM || id;
> INSERT INTO MEMBERS VALUES(id_mem, fn, sn, fln, sln);
> end^
>
> I've tried declaring a variable instead of using id_mem and assigning
> the variable to id_mem after the insert but same error...

In SQL statements, prefix variables and parameters with ":" ...


> INSERT INTO MEMBERS VALUES(:id_mem, :fn, :sn, :fln, :sln);


Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com