Advanced Reporting on Email Field in Accounts Module

I am looking to create an Advanced Report but need some assistance with the SQL formula.

The Accounts Module allows you to add multiple email addresses, but with out of the box reporting it will only pull the primary email. I need it to pull each email listed.

Defined by:

Type=Current Customer

Display Columns:

Account Number

Account Name

Email Address

Can someone help bet me started in creating a query for this?

  • hi Brianna,

    If you don't mind, can I ask why you need to extract these or report?
    ... and wouldn't multiple emails be best if related to Contacts intead?

  • We are looking to pull a report on these emails so that we can use them to send out notifications and updates to clients. Many of the emails that we have are general and not necessarily related to a contact. It also will be a general landing place for all of our internal departments to reference.

  • My apologies if I'm going into obvious detail, I don't know your level of familiarity with Sugar's Studio and database table structure.

    Here is a starting point:

    All relationships between modules and email_addresses are via the  email_addr_bean_rel table where there are three essential columns:

    email_address_id (links to email_addresses)

    bean_module (the name of the module the address is on, for example "Contacts", "Accounts" etc)

    bean_id (the id of the record the email_address is on)

    So your query will look something like:

    from accounts
    join accounts_cstm on accounts_cstm.id_c =
    join email_addr_bean_rel on email_addr_bean_rel.bean_id = 
    	 and email_addr_bean_rel.bean_module = 'Accounts' 
    	 and email_addr_bean_rel.deleted = 0
    join email_addresses on = email_addr_bean_rel.email_address_id
         and email_addresses.deleted = 0
    where accounts.deleted = 0
    and account.account_type = 'CurrentCustomer'

    Note that I added accounts_cstm which is the table where your custom fields for Accounts are stored. I am assuming the Account Number is a custom field. I am also assuming that your field name is account_number_c (this is a big assumption).

    To see the name of the field from your instance, you can use Studio (Admin->Studio->Accounts->Fields) or open an account record view, right click on that field's label and "Inspect", in the "Elements" tab of your tools you will see something like:


    As for the "Current Customer" value, you will need to check what you are using for the actual value stored in the database: go to


    just below the "Drop down List" is an Edit button, click that and it will show you all the values and labels.

    Use the value on the left, in bold, as the value for the filter.

    Hope this helps you get what you need.