Advertisement
matthewpoer

Adjust Contact Assignment to Match Parent Account Assignment

Mar 4th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.97 KB | None | 0 0
  1. select count(*) from contacts
  2. join accounts_contacts on contacts.id = accounts_contacts.contact_id
  3. join accounts on accounts.id = accounts_contacts.account_id
  4. where contacts.deleted = 0 and accounts.deleted = 0 and accounts_contacts.deleted = 0
  5. and (contacts.assigned_user_id <> accounts.assigned_user_id OR
  6.     contacts.team_id <> accounts.team_id OR
  7.     contacts.team_set_id <> accounts.team_set_id);
  8.  
  9.  
  10. update contacts
  11. join accounts_contacts on contacts.id = accounts_contacts.contact_id
  12. join accounts on accounts.id = accounts_contacts.account_id
  13. set contacts.assigned_user_id = accounts.assigned_user_id,
  14.     contacts.team_id = accounts.team_id,
  15.     contacts.team_set_id = accounts.team_set_id,
  16.     contacts.date_modified = NOW()
  17. where contacts.deleted = 0 and accounts.deleted = 0 and accounts_contacts.deleted = 0
  18. and (contacts.assigned_user_id <> accounts.assigned_user_id OR
  19.     contacts.team_id <> accounts.team_id OR
  20.     contacts.team_set_id <> accounts.team_set_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement