I am trying to copy content from a column in one table to another and at the same time I want to populate the primary key column with an incremental number for each row created:
I tried to do the following:
INSERT INTO Table1 (col1, col2) VALUES((SELECT col1 FROM table2), (SELECT NEXTVAL FOR col2_SEQ FROM sysibm.sysdummy1));
but get the following error:
DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0348N "NEXTVAL FOR col2_SEQ" cannot be specified in this context. SQLSTATE=428F
It seems like I can't use the sequence value this way, is there any other way to achieve what I'm trying to do? I just need col2 in table1 to populate a unique BIGINT for each new record from col1 from table2
source share