mtlsql (6/28/2015)
I have a hard time understanding your example, so I don't know if this is the answer you're looking for, but have you looked into the syntax for a MERGE statement? It gives you a lot of control over moving data from one table into another. When the data is not matched (doesn't exist in the destination table), you can do an INSERT, whereas if the data is matched (duplicate row), you can update it. There's more information here, give it a go...https://msdn.microsoft.com/en-us/library/bb510625(v=sql.105).aspx
I agree. A merge should work. An example is below:
merge into table1 u -- destination table
using table2 uq -- source table
on u.account_number=uq.account_number -- condition to test
when not matched then insert
(
account_name,
account_number,
affiliate,
email_address,
phone_number,
staff_number,
create_date)
values (
uq.account_name,
uq.account_number,
uq.affiliate,
uq.email_address,
uq.phone_number,
uq.staff_number,
uq.create_date);
Br. Kenneth Igiri
https://kennethigiri.com
All nations come to my light, all kings to the brightness of my rising