Midrange News for the IBM i Community

Posted by: neilrh
Jackson, MI
Fetch Identity value of record just added.
has no ratings.
Published: 13 Jun 2014
Revised: 20 Jun 2015 - 1468 days ago
Last viewed on: 21 Jun 2019 (2903 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Fetch Identity value of record just added. Published by: neilrh on 13 Jun 2014 view comments(2)

We know that we can access the Identity value using: values IDENTITY_VAL_LOCAL() into :IdentVal. This needs to be performed immediately following the Insert into....

But there is an alternative:

select Identity into :IdentVal from final table (insert into TABLE (field1, .......) Values (:Data, ......))

Obviously need to check sqlcode/sqlstate for success, but the entire insert and tell me what the value of the Identity field was is performed in a single sql action.

Return to midrangenews.com home page.
Sort Ascend | Descend