« Blog Search Added | Main | History Tab Filtering »

Great SQL Query - All Primary & Additional Contacts

Here's a handy SQL Query for you.  It will show all primary and secondary contacts in the database.  If the secondary contact has an address it'll display that address and if they don't it'll use the address information from the primary contact.  To use go to:

Lookup | SQL Query then paste this into the box and hit query.  I tested this on 6.7 SQL 2000 & 7.0 SQL 2005.  It won't work on dBASE.

select company, contact, title, address1, address2, address3, city, state, zip, phone1, contact1.accountno from contact1
union
select contact1.company, contsupp.contact, contsupp.title, contact1.address1, contact1.address2, contact1.address3, contact1.city, contact1.state, contact1.zip, contsupp.phone, contact1.accountno from contact1, contsupp where rectype = 'C' and (contsupp.address1 is null or contsupp.address1 <= '') and contact1.accountno = contsupp.accountno
union
select contact1.company, contsupp.contact, contsupp.title, contsupp.address1, contsupp.address2, contsupp.address3, contsupp.city, contsupp.state, contsupp.zip, contsupp.phone, contact1.accountno from contact1, contsupp where rectype = 'C' and contsupp.address1 > ' ' and contact1.accountno = contsupp.accountno
order by company, contact

Comments (1)

Mihaela:

Hi Chad,
I need some help if you have some time. We have upgraded from 6.6 to 7 (incremental 6.7 and 7). We have about 1000 queries and they don't work any more. The back end is SQL 2005. All queries are old and have " instead of '. Is there a way to change them all in one shot, or do we have to go through each of them manually?

Thank you,
Mihaela

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on September 25, 2006 6:19 PM.

The previous post in this blog was Blog Search Added.

The next post in this blog is History Tab Filtering.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.34