CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Query to set "use household address" for all existing individual contacts
Pages: [1]

Author Topic: Query to set "use household address" for all existing individual contacts  (Read 1011 times)

barneson

  • Guest
Query to set "use household address" for all existing individual contacts
January 22, 2008, 08:05:30 am
I have a CiviCRM installation with about 10,000 individual contacts belonging to ~7,000 households. I want to set all the individual contacts to use this household mailing address. Rather than editing each record through the web interface, I'm in search of a MySQL snippet or custom PHP code to run directly against the database.

Does anyone have a working query or script (or the beginnings of one) that they would be willing to share?

Thanks in advance-
BA

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Query to set "use household address" for all existing individual contacts
January 22, 2008, 05:33:45 pm
I don't have a query or script - but the steps are something like this - assuming you've used the default "Member of Household" relationship type to identify the households which your individual contacts "belong to":

* Select and Loop over your civicrm_relationship records where relationship_type_id = 7.
* For each record, select id from civicrm_individual where civicrm_individual.contact_id = civicrm_relationship.contact_id_a
* Update civicrm_individual set mail_to_household_id = civicrm_relationship.contact_id_b
* Copy the values from the household contact's (civicrm_relationship.contact_id_b) primary civicrm_location and related civicrm_address record to the individual contact's location and address (these will be handled "read-only" values for the individual contacts).

Hope that helps a bit.
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Query to set "use household address" for all existing individual contacts

This forum was archived on 2017-11-26.