Results 1 to 4 of 4

Thread: SQL Puzzle. Removing Contacts from a Prospect List when they have no email address.

  1. #1
    hkphooey is offline Sugar Community Member
    Join Date
    Jan 2007
    Posts
    94

    Default SQL Puzzle. Removing Contacts from a Prospect List when they have no email address.

    Hi all.

    I've been struggling with the labyrinthine database structure of SugarCRM all afternoon and I'm going SQL blind. I wondered if anyone else had tried to do this.

    So, as the title suggests, a bunch of contacts were added to a Target List. Since then the data has been tidied up and I'd like to remove all the contacts on the target list which don't have email addresses. There are 4000 people on the list, so this is clearly not a manual process, especially as the Target list module will only show 20 names at a time.

    So, while it was easy to add multiple names to a target list using Mass Update and Power Prospecting, it is hard to maintain those lists.

    First stop was of course through the Web Interface. I can use Advanced search to get all the people on a target list. However.
    a) I can't find all those who have an empty email address and
    b) I can't sort by email address in the results and
    c) Even if I could get all the empty email addresses selected, there is no way of doing a mass update to remove them from a Target List.

    So, database it is then ....

    First I got the id of the Target list, which by the time you're in the database is called a prospect list.
    Code:
    SELECT * FROM `prospect_lists
    Which gave me the prospect list id. A quick check then ...
    Code:
    SELECT * 
    FROM prospect_lists_prospects
    WHERE prospect_list_id ="4d850c13-7da3-5aac-b39a-4ae7fb91d055"
       AND related_type = "Contacts"
       AND deleted=0
    Yup, that's the list I want. But there's no easy path from here, so what I planned to do is get all the ids of contacts with an empty email address ...
    Code:
    SELECT contacts.id
    FROM contacts 
      LEFT JOIN email_addr_bean_rel on contacts.id=email_addr_bean_rel.bean_id 
      LEFT JOIN email_addresses on email_addr_bean_rel.email_address_id=email_addresses.id 
    WHERE email_addresses.email_address IS NULL
    And then use that to delete the 'No Email Address' Contacts from the table which associates contacts with prospect lists eg.
    Code:
    DELETE FROM prospect_lists_prospects
    WHERE prospect_lists_prospects.related_id IN 
    ("10770f41-c3fa-9e47-d386-4a4993d8a378", ...etc...."10a6006b-fbb7-ad2a-a4ff-4a498dabeb43")
    Well that looked good, except it still leaves a bunch of contacts who used to have email addresses associated with them, and which was deleted. However, the pointer in email_addr_bean_rel is still there so the email address is picked up.

    I've tried limiting the query with email_addresses.deleted =1 but that doesn't work -- email addresses are not marked with deleted=1 when they're deleted (! apparently ...) and
    email_addr_bean_rel.deleted = 1 doesn't help either.

    Where do I go from here ...

  2. #2
    salesagility's Avatar
    salesagility is offline Sugar Community Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    2,379

    Default Re: SQL Puzzle. Removing Contacts from a Prospect List when they have no email addres

    you could try installing Enhanced Search from SugarForge and then searching for all email address NOT %@% which should return all the empty addresses.

  3. #3
    christianknoll's Avatar
    christianknoll is offline Sugar Community Member
    Join Date
    Nov 2008
    Location
    Vienna
    Posts
    939

    Default Re: SQL Puzzle. Removing Contacts from a Prospect List when they have no email addres

    What you are looking for is a not exists clause .. you can use our reporter ... http://www.sugarforge.org/projects/kinamureporter/ .. this will allow you to do exactly that srearch witha nonexists clause without the need to understand the slightes bit about SQL ... ....

    regard, christian.

    http://www.kinamu.com

    Quote Originally Posted by hkphooey View Post
    Hi all.

    I've been struggling with the labyrinthine database structure of SugarCRM all afternoon and I'm going SQL blind. I wondered if anyone else had tried to do this.

    So, as the title suggests, a bunch of contacts were added to a Target List. Since then the data has been tidied up and I'd like to remove all the contacts on the target list which don't have email addresses. There are 4000 people on the list, so this is clearly not a manual process, especially as the Target list module will only show 20 names at a time.

    So, while it was easy to add multiple names to a target list using Mass Update and Power Prospecting, it is hard to maintain those lists.

    First stop was of course through the Web Interface. I can use Advanced search to get all the people on a target list. However.
    a) I can't find all those who have an empty email address and
    b) I can't sort by email address in the results and
    c) Even if I could get all the empty email addresses selected, there is no way of doing a mass update to remove them from a Target List.

    So, database it is then ....

    First I got the id of the Target list, which by the time you're in the database is called a prospect list.
    Code:
    SELECT * FROM `prospect_lists
    Which gave me the prospect list id. A quick check then ...
    Code:
    SELECT * 
    FROM prospect_lists_prospects
    WHERE prospect_list_id ="4d850c13-7da3-5aac-b39a-4ae7fb91d055"
       AND related_type = "Contacts"
       AND deleted=0
    Yup, that's the list I want. But there's no easy path from here, so what I planned to do is get all the ids of contacts with an empty email address ...
    Code:
    SELECT contacts.id
    FROM contacts 
      LEFT JOIN email_addr_bean_rel on contacts.id=email_addr_bean_rel.bean_id 
      LEFT JOIN email_addresses on email_addr_bean_rel.email_address_id=email_addresses.id 
    WHERE email_addresses.email_address IS NULL
    And then use that to delete the 'No Email Address' Contacts from the table which associates contacts with prospect lists eg.
    Code:
    DELETE FROM prospect_lists_prospects
    WHERE prospect_lists_prospects.related_id IN 
    ("10770f41-c3fa-9e47-d386-4a4993d8a378", ...etc...."10a6006b-fbb7-ad2a-a4ff-4a498dabeb43")
    Well that looked good, except it still leaves a bunch of contacts who used to have email addresses associated with them, and which was deleted. However, the pointer in email_addr_bean_rel is still there so the email address is picked up.

    I've tried limiting the query with email_addresses.deleted =1 but that doesn't work -- email addresses are not marked with deleted=1 when they're deleted (! apparently ...) and
    email_addr_bean_rel.deleted = 1 doesn't help either.

    Where do I go from here ...

  4. #4
    hkphooey is offline Sugar Community Member
    Join Date
    Jan 2007
    Posts
    94

    Default Re: SQL Puzzle. Removing Contacts from a Prospect List when they have no email addres

    Actually, no, neither of those solutions will work for me. As I mentioned earlier:
    c) Even if I could get all the empty email addresses selected, there is no way of doing a mass update to remove them from a Target List.
    So I'm still looking for a solution here from someone who knows how the database works.

    Or maybe this is a bug. Maybe email_addresses.deleted should be tagged in this instance, when an email address is removed from a contact, and it isn't happening?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 2011-11-21, 05:17 PM
  2. Replies: 5
    Last Post: 2009-02-03, 03:13 PM
  3. Exporting prospect list contacts
    By brob in forum General Discussion
    Replies: 2
    Last Post: 2006-08-23, 04:53 AM
  4. Replies: 0
    Last Post: 2006-06-13, 08:44 PM
  5. Transfer a prospect address to contacts
    By Ericmuc in forum Marketing/Campaign Management
    Replies: 1
    Last Post: 2005-05-04, 02:03 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •