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 (Moderator: Dave Greenberg) »
  • Finding & editing names/addresses w/ all upper/all lower case, how do you do it?
Pages: [1]

Author Topic: Finding & editing names/addresses w/ all upper/all lower case, how do you do it?  (Read 660 times)

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Finding & editing names/addresses w/ all upper/all lower case, how do you do it?
October 06, 2013, 08:10:11 pm
Whenever you have a lot of contacts entering or editing their own data, a common situation is to have a lot of names & addresses entered in all upper or all lower case:

Quote
JOHN SMITH
john smith

How do you all find these problem entries so that you can update/edit them?

Here is the method I've been using--it is, to say the least, super-kludgy.

1. Open PHPMyAdmin and do this search:

Code: [Select]
SELECT id FROM `civicrm_contact` where
(binary first_name REGEXP '^[[:lower:]]+$'
OR binary first_name REGEXP '^[[:upper:]]+$'
OR binary last_name REGEXP '^[[:lower:]]+$'
OR binary last_name REGEXP '^[[:upper:]]+$'
OR binary organization_name REGEXP '^[[:lower:]]+$'
OR binary organization_name REGEXP '^[[:upper:]]+$' )
AND is_deleted !=1

2. Then export the results, which is a list of contact IDs that have the all upper/all lower situation.  I export as CVS and then open that with a text editor.  With a little massaging, find/replace, etc., it's pretty easy to get the list of numbers into this format:  (3,5,27,300,403,424,1000,2301).  (Obviously, I have a lot more in my list, about 100 or 200 typically.)

3. In CiviCRM, open search builder and enter:

Code: [Select]
   Individual, Internal contact id, IN
and then paste your list of contact IDs into the form: (3,5,27,300,403,424,1000,2301)

4. Search.  Then "All X records" and "Batch Update Via Profile".  I use a profile that has first, middle, last, and nicknames as well as some other fields. 

So then I can quickly & easily edit the names of up to 100 contacts at a time.

5. When finished editing the profiles, which takes care of all individual contacts, re-do the search builder with:

Code: [Select]
   Individual, Internal contact id, IN  and enter the same list of contact IDs.
This will pick up all the Organization contacts and you can repeat the same process of editing the contacts via profile.  If you have Household contacts, you'll need to do the search & the profile editing steps again for those, as well.

So, that is my kludgy solution.  Anyone have any better ones--this has got to be a common business process CiviCRM users need!

Also--this works only for contact names.  What about addresses?  Obviously, a similar strategy could work for them.  But there must be an easier way!
« Last Edit: October 06, 2013, 08:47:42 pm by flug »

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Re: Finding & editing names with all upper/all lower case, how do you do it?
October 06, 2013, 08:42:45 pm
FYI you can *almost* do this within search builder.  You do a search like this:

Code: [Select]
Individual, Last Name, RLIKE, [[:digit:]]
(Finds any last name with at least one digit in it.)

Or

Code: [Select]
Individual, Last Name, RLIKE, ^[[:digit:]]+$
(Finds any last name made up completely of digits.)

Both of these searches are quite useful, by the way--spammers like to use digits in the names they enter.

However if you try to do a search like this, it will fail:

Code: [Select]
Individual, Last Name, RLIKE, ^[[:upper:]]+$
Code: [Select]
Individual, Last Name, RLIKE, ^[[:lower:]]+$
The reason for the failure is the collation we use for the civicrm_contact table is case insensitive.

There are two possible solutions I know of--but you can't get either to work in search builder as far as I know:

  • Use a different collation for the query--one that is case sensitive
[li]Cast the field to binary during the query, like

[/li][/list]
Code: [Select]
SELECT id FROM `civicrm_contact` where
binary first_name REGEXP '^[[:lower:]]+$'
    The binary cast makes the operations case sensitive.
    [/li]


FYI information about character classes ([:upper:] and the like) in SQL REGEX and RLIKE expressions is here: http://dev.mysql.com/doc/refman/5.5/en/regexp.html

Info about casting values to binary is here: http://dev.mysql.com/doc/refman/5.5/en/cast-functions.html

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Re: Finding & editing names/addresses w/ all upper/all lower case, how do you do it?
October 06, 2013, 08:51:37 pm
Here is a query that will find addresses & cities that are all upper or all lower case:

Code: [Select]
SELECT cc.id FROM `civicrm_contact` cc
left join civicrm_address ca on cc.id=ca.contact_id
where
(binary ca.street_address REGEXP '^[[:lower:]]+$'
OR binary ca.street_address REGEXP '^[[:upper:]]+$'
OR binary ca.city REGEXP '^[[:lower:]]+$'
OR binary ca.city REGEXP '^[[:upper:]]+$'
)
AND cc.is_deleted !=1
AND ca.is_primary = 1

Just as with my procedure above for editing names, export the list of contact IDs, format them to use in the Search Builder "IN" query, and then edit the address records using "Batch Update via Profile".

flug

  • I post frequently
  • ***
  • Posts: 126
  • Karma: 12
Re: Finding & editing names/addresses w/ all upper/all lower case, how do you do it?
October 06, 2013, 09:21:45 pm
Improved version of the above:

Here is a query that will find addresses & cities that are all upper or all lower case:

Code: [Select]
SELECT cc.id FROM `civicrm_contact` cc
left join civicrm_address ca on cc.id=ca.contact_id
where
(binary ca.street_address = UPPER(ca.street_address)
OR binary ca.street_address = LOWER(ca.street_address)
OR binary ca.city = LOWER(ca.city)
OR binary ca.city = UPPER(ca.city)
)
AND cc.is_deleted !=1
AND ca.is_primary = 1

 * Just as with my procedure above for editing names, export the list of contact IDs, format them to use in the Search Builder "IN" query, and then edit the address records using "Batch Update via Profile".

 * The "binary ca.city = LOWER(ca.city)" formula may work better than using the [:upper:] formula.  It will catch "NEW YORK CITY" for example, whereas the [:upper:] formula won't.
« Last Edit: January 08, 2015, 08:32:06 pm by flug »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Finding & editing names/addresses w/ all upper/all lower case, how do you do it?
October 07, 2013, 03:24:59 am
Everybody seems to have their own hack for this, myself included. Would be nice if one of us would package it as an extension. I've been meaning to for some time, we'll see if I have some time at the sprint tis week...
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Finding & editing names/addresses w/ all upper/all lower case, how do you do it?

This forum was archived on 2017-11-26.