Gurus,

I have a question about dynamically generate the update statment:

I have two tables, both tables have the exact same columns (and primary key), we want to achieve the following target:

some program will insert rows into the first table, only some of the columns has not null values, I need to have a stored procedure to update the second table based on which columns of the first table has not null values, for example,

if the following columns are not null:
table1.id (primary key)
table1.col2
table1.col4

The update statement should be:

update table2 set
table2.col2=table1.col2
table2.col4=table1.col4
where table2.id=table1.id

if the following columns are not null:
table1.id (primary key)
table1.col2
table1.col4
table1.col6

The update statement should be:

update table2 set
table2.col2=table1.col2
table2.col4=table1.col4
table2.col6=table1.col6
where table2.id=table1.id

Thank you very much!!