Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » DB2 insert question

This thread is locked; no one can reply to it. rss feed Print
DB2 insert question
Steve Terry
Member #1,989
March 2002
avatar

I have a simple table in DB2 with an identity column and I know I can do a select from final table on insert to get all of the new ID's for mass inserting new records from a select. However, I want to also be able to retrieve the old identity value as well in a separate column. Is this possible?

WITH TEMP(ID, PART_ID, OLD_ID) AS
(
SELECT ID, PART_ID, ??? AS OLD_ID
FROM FINAL TABLE
(
INSERT INTO SOME_TABLE
(
PART_ID
)
(
SELECT DISTINCT PART_ID
FROM SOME_TABLE
WHERE SOME_CONDITION
)
)
)
SELECT * FROM TEMP;

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Go to: