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 / May 2006

Tip: Looking for answers? Try searching our database.

Showing most recent record for each employee in a query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
CEV - 30 May 2006 15:48 GMT
I am working with the following Query:

SELECT tblEmployees.LastName, tblEmployees.FirstName,
tblPositions.Department, tblEmployeePositions.Status,
tblEmployeePositions.PositionHours,
tblEmployeePositions.PositionNumber, tblEmployees.DateofHire,
tblEmployees.DateLeftAgency
FROM tblPositions INNER JOIN (tblEmployees INNER JOIN
tblEmployeePositions ON tblEmployees.EmployeeNumber =
tblEmployeePositions.EmployeeNumber) ON
tblPositions.PositionNumber =
tblEmployeePositions.PositionNumber
WHERE (((tblEmployees.DateLeftAgency) Between
[Forms]![frmSelectDateRange]![txtBeginDate] And
[Forms]![frmSelectDateRange]![txtEndDate]) AND
((tblEmployees.Terminated)=Yes))
ORDER BY tblPositions.Department;

I have a form based on the table tblEmployees. Within this form I
have a subform displaying in table view the info from the table
tblEmployeePositions for the Employee selected in the main form.
The above Query shows me info for everyone that was terminated
for the dates I specify. The problem is that over a period of
time an employee may have had more then one position. This Query
is showing me info for every position that employee has ever had. I
only want it to show me the latest position held by each employee that is
called up by the query. How can I do
this?

Thank You for your help,

CEV
John Spencer - 30 May 2006 18:03 GMT
Do you have some date field or other field that lets you determine the last
position the employee held?  Assuming that you have a field named
PositionStartDate in tblEmployeePositions.

SELECT tblEmployees.LastName
, tblEmployees.FirstName
, tblPositions.Department
, tblEmployeePositions.Status
, tblEmployeePositions.PositionHours
, tblEmployeePositions.PositionNumber
, tblEmployees.DateofHire,
tblEmployees.DateLeftAgency
FROM tblPositions INNER JOIN (tblEmployees INNER JOIN
tblEmployeePositions ON tblEmployees.EmployeeNumber =
tblEmployeePositions.EmployeeNumber) ON
tblPositions.PositionNumber =
tblEmployeePositions.PositionNumber
WHERE (((tblEmployees.DateLeftAgency) Between
[Forms]![frmSelectDateRange]![txtBeginDate] And
[Forms]![frmSelectDateRange]![txtEndDate]) AND
((tblEmployees.Terminated)=Yes)) AND
tblEmployeePositions.PositionStartDate  =
  (SELECT Max(Temp.PositionStartDate)
   FROM tblEmployeePositions as Temp
  WHERE Temp.EmployeeNumber = tblEmployeePositions.EmployeeNumber)
ORDER BY tblPositions.Department;

>I am working with the following Query:
>
[quoted text clipped - 28 lines]
>
> CEV
CEV - 30 May 2006 22:15 GMT
Thank You very much John. That did exactly what I wanted it to.

Thanks,

CEV

> Do you have some date field or other field that lets you determine the
> last position the employee held?  Assuming that you have a field named
[quoted text clipped - 55 lines]
>>
>> CEV
 
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.