Midrange News for the IBM i Community


Posted by: neilrh
A/P
Jackson, MI
Fetch Identity value of record just added.
has no ratings.
Published: 13 Jun 2014
Revised: 20 Jun 2015 - 888 days ago
Last viewed on: 24 Nov 2017 (2329 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

COMMENTS

(Sign in to Post a Comment)
Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Fetch Identity value of record just added.
Posted: 3 years 5 months 12 days 18 hours 2 minutes ago

Where's the "Like" button on this thing. cool

Posted by: DaleB
Premium member *
Reading, PA
Comment on: Fetch Identity value of record just added.
Posted: 3 years 5 months 9 days 9 hours 20 minutes ago

That's pretty cool