|
-
Sep 24th, 2002, 03:55 PM
#1
Thread Starter
Lively Member
*RESOLVED* Rec set f/ Report from multiple tables
I am still searching for the answer to this question (have tried SQL forums elsewhere, but no one is responding 'yay' or 'nay')
What I need is - given a company ID, find all the records tied to that company across 4 tables. That much I can do.
The problem is I need to take a piece of that result (a contact name) and look up their address in same table the company's address came out of.
I have tried referencing the table twice, once by name and once by alias and use the alias for the contact info.
And that NEARLY works! Except it returns multiple records (it should return a single record with two distinct addresses within that record). What I actually get is the company info, complete with company address, repeated 6 times with 6 different contact names and their subsequent addresses!!!
It is returning the correct company based on the ID passed to the query, but then returns EVERY contact in the sample database, rather than the single contact which is tied to that company.
It looks messy, but here is the query string:
Code:
SELECT tblCorp.*, tblOrganization.*, tblStateReports.*,
tblAddressBook.Address1Mailing,
tblAddressBook.Address1Main,
tblAddressBook.Address2Mailing,
tblAddressBook.Address2Main, tblAddressBook.Attorney,
tblAddressBook.CityMailing, tblAddressBook.CityMain,
tblAddressBook.EmailAddress, tblAddressBook.FAXNumber,
tblAddressBook.FullName, tblAddressBook.ID,
tblAddressBook.PrimaryPhone,
tblAddressBook.RegisteringAgent,
tblAddressBook.SecondaryPhone,
tblAddressBook.StateMailing, tblAddressBook.StateMain,
tblAddressBook.ZIPMailing, tblAddressBook.ZIPMain,
RegAddress.FullName AS RegAgent,
RegAddRess.Address1Reg, RegAddress.Address2Reg,
RegAddress.CityReg, RegAddress.StateReg,
RegAddress.ZIPReg
FROM tblAddressBook, tblCorp, tblOrganization, tblStateReports,
tblAddressBook AS RegAddress
WHERE (tblAddressBook.ID = tblCorp.ID AND
tblCorp.ID = tblOrganization.ForeignKey AND
tblOrganization.ID = tblStateReports.ForeignKey AND
tblCorp.ID = ? AND tblOrganization.OrganizedAuthorized = 'O')
AND (tblCorp.ID = ? AND RegAgent = tblCorp.RegisteredAgent)
HELP! I need to deliver this report TOMORROW and I can't make the stinking thing work
Last edited by mdsoren; Sep 25th, 2002 at 05:51 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|