Subject ID of latest record just inserted
Author rebel_rob_98
Hello All,

This is probably an easy questions, so please be forgiving :)

I have a stored procedure that takes in info, inserts it into the DB
and I want to return the ID of the record that was just inserted.
Here is a sample chunk of code:

SELECT gen_id(TMP_SOME_GEN, 1) as Result
FROM RDB$Database
INTO :tcbid;
INSERT INTO tmp_some_table
(field1,
field2,...

This code works and does not throw an error however the ID (tcbid)
does not match that of the one just inserted (it's one digit behind).
So, my solution was this:

...
decalre variable finalid integer;
...
SELECT gen_id(TMP_SOME_GEN, 0) as Result
FROM RDB$Database
INTO :tcbid;

finalid = tcbid + 1;

INSERT INTO tmp_some_table
(field1,
field2,...

The method listed above gets me the correct ID of the record being
inserted, however I am not sure this is the best course of action.

Any tips or suggestions are greatly appreciated.

Thank you for your time,

Robert