We help IT Professionals succeed at work.
Get Started

SQL Code

196 Views
Last Modified: 2012-05-12
Hi,

I'm trying to create an excel sheet of people's contact details, employment, and notes from our database.

The code is below and some of the results I get are attached.

I have about 28K people in the contact database yet I'm getting over 408K results in my search because people have multiple long note entry in the History tab.

How do I code it so I get about 28K results with the various long note entries for each person in their own column?

For example:

FAKE NAME 1 | LONGNOTES1a | LONGNOTES1b| LONGNOTES1c | LONGNOTES1d |
FAKE NAME 2 | LONGNOTES2a | LONGNOTES2b| LONGNOTES2c | LONGNOTES2d |

Thanks,
Primus



select sysdba.CONTACT.PREFIX,
sysdba.CONTACT.FIRSTNAME,
sysdba.CONTACT.LASTNAME,
sysdba.CONTACT.SUFFIX,
sysdba.CONTACT.TITLE,
sysdba.ACCOUNT.ACCOUNT,
sysdba.CONTACT.WORKPHONE,
sysdba.CONTACT.HOMEPHONE,
sysdba.CONTACT.MOBILE,
sysdba.CONTACT.EMAIL,
sysdba.CONTACT.SECONDARYEMAIL,
sysdba.ADDRESS.ADDRESS1,
sysdba.ADDRESS.ADDRESS2,
sysdba.ADDRESS.CITY,
sysdba.ADDRESS.STATE,
sysdba.ADDRESS.POSTALCODE,
sysdba.ADDRESS.COUNTRY,
sysdba.CONTACT.STATUS,
sysdba.HISTORY.LONGNOTES from sysdba.CONTACT
LEFT JOIN sysdba.ACCOUNT on sysdba.CONTACT.ACCOUNTID = sysdba.ACCOUNT.ACCOUNTID
LEFT JOIN sysdba.ADDRESS on sysdba.CONTACT.ADDRESSID = sysdba.ADDRESS.ADDRESSID and sysdba.ADDRESS.ISPRIMARY = 'T'
LEFT JOIN sysdba.HISTORY on sysdba.CONTACT.CONTACTID = sysdba.HISTORY.CONTACTID

Open in new window

Book1.xlsx
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE