Say I have table MyFile, with key column a.
And all rows where a = 'old', I want to clone with a = 'new', within an SQLRPGLE program.
The simple way:
But this is frustrating because it means you have to specify all the columns, so the program needs recompiling to account for new columns.
I thought of this way:
Which works, but it's a 4 step process that requires copying all the records to another table before copying them to the main table
Is there a better way?
And all rows where a = 'old', I want to clone with a = 'new', within an SQLRPGLE program.
The simple way:
Code:
exec sql insert into MyTable (a, b, c, d) select 'new', b, c, d from MyTable where a = 'old';
I thought of this way:
Code:
exec sql declare global temporary table MyTable# as ( select * from MyTable where a = 'old') with data; exec sql update QTEMP/MyTable# set a = 'new'; exec sql insert into MyTable select * from QTEMP/MyTable#; exec sql drop table QTEMP/MyTable#;
Is there a better way?
Comment