tags:

views:

42

answers:

2

Hi, i want to get the value of the last id insert in a table. How i can do this?

+1  A: 
SELECT IDENTITY_VAL_LOCAL() AS VAL FROM SYSIBM.SYSDUMMY1

See docs.

Bill Karwin
SYSDUMMY1? i can't find that table in the sysibm schema... :)
Enrique San Martín
Are you being ironic? See http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0002369.html
Bill Karwin
A: 

Well the solution that i use is:

select id from NEW TABLE (insert into (val1, val2, ...) values ('lorem', 'ipsum', ...)

this get the id column from the last row inserted in the DB :)

Enrique San Martín