Monday, April 16, 2012

Merging two table in sqlplus

I have two tables with same structure:
masterTable (id, description, list_price)
and
changesTable (id, description, list_price)



I want to merge changes from changesTable into masterTable, but I don't want to update 'description' in masterTable when it is NULL in changesTable, I want to keep old value



I tried to do this



WHEN MATCHED THEN
UPDATE SET master.list_price=changes.list_price,
master.description=ch.description
WHERE length(changes.description)>0


but in this case the list_price doesn't get updated as well.



How can I merge them properly?
Thanks





No comments:

Post a Comment