Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL Join question

Author  Topic 

HockeyFan
Starting Member

26 Posts

Posted - 2006-03-05 : 13:09:45
I don't do SQL on a regular basis and don't really know much about JOINs. Can someone help me form a proper SQL statement to achieve what I need.

I have to do a search on any or all of:
Lastname, firstname, active , contacttype, organization

I know there will be multiple sql statements, but I figured if I could get one, I could figure out the rest.

Table A.Firstname, Lastname, ContactID, ActiveIndicator
Table B.ID, ContactID, ContactTypeID
Table C.ContactTypeID, Description
Table D.ContactID, OrgID
Table E.OrgID, OrgName

So in my first search, what if I have the ContactID from Table A. Now what?
In this case, I know the contact is Active because I have that in Table A. However, I don't have ContactType, or the Organization name. I guess it's possible that there could be more than one.

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2006-03-06 : 00:06:19
Try this..
Select A.Firstname, A.Lastname , A.activeIndicator, B.contacttype, E.orgname as organization
from TableA A
inner join TableB B
on A.ContactId = .ContactId
inner join TableC C
On B.ContactId = C.ContactId
inner join TABLED D
on C.ContactId = D.ContactId
inner join TABLEE E
on D.ORGID = E.ORGID
where A.contactID = <?>
Go to Top of Page
   

- Advertisement -