Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Mark non-matching records in two databases

Author  Topic 

kreisel
Starting Member

2 Posts

Posted - 2011-08-28 : 17:26:59
I have two databases (db_A, db_B) both with similar tables called customer (they are not exact but have many similar columns).

I want to select certain records in db_A where globalcustomer=0, then based on the column accountnumber, determine if that record exists in db_B. If it does not, I want update an unused field customtext4='delete' (in db_A).

I can then decide if I want to delete those marked records using additional SQL which I already understand.

Can anyone help?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-08-28 : 17:46:46
update a
set customtext4='delete'
from db_A..customer as a
where globalcustomer=0
and not exists(select * from db_B..customer as b where b.accountnumber=a.accountnumber)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

kreisel
Starting Member

2 Posts

Posted - 2011-08-28 : 23:57:20
Exactly what I needed. Thanks!
Go to Top of Page
   

- Advertisement -