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)
 How to build a select statement to handle these joins

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-07-08 : 12:03:04
Dennis writes "I do not know if I can explain my problem properly. but I'll give it a try.

I have 4 Tables a Volunteer table, an Assignment (Master Table) and an Assignment_Detail (Detail Table).
And a Join Table that holds the Keys to each table. ie: VolID, ItemID,
DetailID

I would like to know how to create a select statement that would return a result that would populate a datalist displaying the Volunteers Name, Email etc for the Volunteer Table, and for the master-detail tables the Title of the Assignment, Description, etc; from the Assignment Table and the details of the Assignment like Date and Time periods that the Volunteer signed up for.


The VolID get the Volunteer Data and the ItemID get the Master Data and the (ItemID and DetailID) gets the Detail Data.

Can someone give me some help on creating the proper way to do this.

The Join Table looks like This

ID        VolID   ItemID DetailID
1 John 1 1
2 John 1 4
3 John 3 2
4 Den 10 1
5 Den 1 1
6 Mary 7 2
7 Mary 1 2
"

JasonGoff
Posting Yak Master

158 Posts

Posted - 2004-07-09 : 04:53:46
Something like...

SELECT V.*, A.*, D.*
FROM Volunteer V
INNER JOIN JoinTable J ON J.VolID=V.VolID
INNER JOIN Assignment A ON A.ItemID=J.ItemID
INNER JOIN Detail D ON D.DetailID=J.ItemID


obviously without a full schema for all the tables I'm not sure the column names etc are correct, but you get the idea.
Go to Top of Page
   

- Advertisement -