Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Help - Tables Relationship

Status
Not open for further replies.

Corneliu

Technical User
Sep 16, 2002
141
US
Can someone please help me with this?
What I have is 1 database, with 10 tables. Each table has its own information, such as location table, technician table, week table, etc etc.
What I want is this:
I am setting to do a query on 3 tables.
Table Technicians, Site, Department and main one is Projects.
The Technicians Table has 2 fields, TechID and Technician.
The Site Table has 2 fields, SiteID and Site
The Projects Table has quite a lot of fields, but the ones above are the one that my problem is with.
Instead of quering the database for the site name, I set it to query for the Site ID, Tech ID, etc etc to make it easier on the server. Now, Each record in the Projects Table has the SiteID, TechID, DepartmentID in the fields Site, Technician, Department.
Depending on the user request (they are searching by Site and Week), I want to display the Name of the Site, the Name of the Technician and the Name of the Department instead of the ID #.
How do I do that? When I do a query in the final page, everything works great but instead of getting the Site Name or Tech Name or Dept Name, I get the ID #.
How can I change that to get the Name from that particular ID. Here is the Code that I have for the query:

<%
Wk = TRIM( Request.QueryString (&quot;Wk&quot;))
Site = TRIM( Request.QueryString (&quot;Site&quot;))
%>

<%

Set RS2 = Server.CreateObject(&quot;ADODB.Recordset&quot;)
SqlString = &quot;SELECT Projects.ProjID, Projects.ProjName, Projects.ProjDate, Projects.Department, Projects.Tech, Projects.TechC, Projects.Hours, Projects.Site, Projects.Week, Projects.ProjCount, Projects.Descript&quot;
SqlString = SqlString & &quot; FROM ((Projects INNER JOIN Department ON Projects.Department = Department.DepartmentID) INNER JOIN Site ON Projects.Site = Site.SiteID) INNER JOIN Technicians ON Projects.Tech = Technicians.TechID&quot;
sqlString = sqlString & &quot; WHERE Week = '&quot; & Wk & &quot;' and Site = '&quot; & Site & &quot;'&quot;

Set RS2 = objConn.Execute ( SqlString )
%>

Displaying the Information:
<% while not RS2.EOF %>

<td><%=RS2(&quot;Department&quot;)%></td>
<td><%=RS2(&quot;Site&quot;)%></td>
<td><%=RS2(&quot;Technician&quot;)%></td>
<td><%=RS2(&quot;Week&quot;)%></td>

Thank You For Your Help...
 
I apologize, but got it to work. I was working on it for too long, walked away and than finally got it.
Thats what happens when you stay in front of the PC for too long, Brain Damage...
Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top