Update and Insert data from a updated table I need help to update (and insert) data in table1 with newer data from table2.

I am in a very hard situation imagine that i will need to do it for 40 tables in a database of more than 300 tables running in production, if i want to do for all tables, i will just delete the database and restore the dump but this is not my case. I am trying to imagine how i can write a function to do this, using a loop for example, checking if the data is newer(update) or inexistent(insert). So i will need a very generic production or to program a very smart function.
Requirements are not clear on insert. 
If the ID are not correct then how would you know a non-matching usercode is not already present?  

Update:
What this does is if t2 is null then it will not replace a value in t1

update t1 
set t1.col1 = insull(t2.col1, t1.col2) .... 
from table1 t1 
join table2 t2 
on t2.usercode = t1.usercode