Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / December 2005

Tip: Looking for answers? Try searching our database.

Returning multiple values with SQL query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AccessNewbie - 30 Nov 2005 18:33 GMT
I have a database with a couple of table. The main table I am working with
(named PR) has one field for the project manager's id number ("projmgr") and
one field for the project supervisor's id number ("supervisor").

The name of the project manager and supervisor are in a second table (named
EM). This table has fields for first name ("firstname"), last name
("lastname"), middle name ("middlename") and id number ("employee").

I would like to do one SELECT statement that will return, among other things
the names of both the project manager and supervisor.

So far I have the following SELECT statement:

SELECT pr.wbs1, pr.wbs2, pr.wbs3, pr.longname, pr.projmgr,
   pr.supervisor, pr.clientid, pr.fee, pr.reimballow, pr.consultfee,
   pr.org, projectcustomtabfields.custhpprojectno as HPNum,
   em.lastname, em.firstname, em.middlename, cl.name as ClientName,
   organization.name as OfficeName FROM pr
LEFT JOIN projectcustomtabfields on (pr.wbs1=projectcustomtabfields.wbs1
   and pr.wbs2=projectcustomtabfields.wbs2 and
pr.wbs3=projectcustomtabfields.wbs3)
LEFT JOIN organization on pr.org= organization.org
LEFT JOIN em on pr.projmgr=em.employee
LEFT JOIN cl on pr.clientid=cl.clientid
WHERE pr.status='A' and pr.org='6501'
ORDER BY pr.wbs1, pr.wbs2, pr.wbs3

This only returns the name of the project manager. How can I also get the
name of the supervisor?

thanks
Duane Hookom - 30 Nov 2005 18:48 GMT
You would need to add the em table into the query one more time and join it
to the supervisor field. Then alias your firstname and lastname fields so
you know which is which.

Signature

Duane Hookom
MS Access MVP

>I have a database with a couple of table. The main table I am working with
> (named PR) has one field for the project manager's id number ("projmgr")
[quoted text clipped - 30 lines]
>
> thanks
AccessNewbie - 30 Nov 2005 19:27 GMT
thanks. However, I'm not sure how this should be done. could you possibly
edit the select statement as you suggested?  thanks

> You would need to add the em table into the query one more time and join it
> to the supervisor field. Then alias your firstname and lastname fields so
[quoted text clipped - 34 lines]
> >
> > thanks
John Spencer - 01 Dec 2005 00:08 GMT
Something like the following:

SELECT pr.wbs1, pr.wbs2, pr.wbs3, pr.longname, pr.projmgr,
   pr.supervisor, pr.clientid, pr.fee, pr.reimballow, pr.consultfee,
   pr.org, projectcustomtabfields.custhpprojectno as HPNum,
   em.lastname, em.firstname, em.middlename, cl.name as ClientName,

   ESuper.LastName as SprLast, ESuper.FirstName as SprFirst, ESuper.Middlename
as SprMiddle,

   organization.name as OfficeName
FROM ((((pr
LEFT JOIN projectcustomtabfields on (pr.wbs1=projectcustomtabfields.wbs1
   and pr.wbs2=projectcustomtabfields.wbs2 and
pr.wbs3=projectcustomtabfields.wbs3))
LEFT JOIN organization on pr.org= organization.org)
LEFT JOIN em on pr.projmgr=em.employee)
LEFT JOIN cl on pr.clientid=cl.clientid)

LEFT JOIN Em as ESuper on PR.Supervisor = ESuper.Employee

WHERE pr.status='A' and pr.org='6501'
ORDER BY pr.wbs1, pr.wbs2, pr.wbs3

> I have a database with a couple of table. The main table I am working with
> (named PR) has one field for the project manager's id number ("projmgr") and
[quoted text clipped - 27 lines]
>
> thanks
AccessNewbie - 01 Dec 2005 13:37 GMT
thanks, that does it. much appreciated.

> Something like the following:
>
[quoted text clipped - 51 lines]
> >
> > thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.