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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In a bad way - Need help with Max Date

Status
Not open for further replies.

HRISmess

MIS
Jun 28, 2005
13
US
The query below identifies the last day an employee is in an EMPL_STATUS of (A or L). I need to now count all employees that were active as of monthend for each month of 2006...and I am stuck!

Do I run a separate query to identify all EEs who have termed and their effective date; then, compare to effective date of the query below?

SELECT A.EMPLID, A.EFFDT, A.EFFSEQ, A.EMPL_STATUS, A.JOBCODE, A.DEPTID
FROM JOB AS A INNER JOIN [SELECT EMPLID, Max(EFFSEQ) As LastSeq, Max(EffDt) As LastDate FROM JOB GROUP BY EMPLID
]. AS L ON (A.EFFDT = L.LastDate) AND (A.EMPLID = L.EMPLID)
WHERE (((A.EMPL_STATUS) In ("A","L")) AND ((A.DEPTID) Like "######10*"))
ORDER BY A.EMPLID;
 


Hi,

try this
Code:
SELECT A.EMPLID, A.EFFDT, A.EFFSEQ, A.EMPL_STATUS, A.JOBCODE, A.DEPTID

FROM JOB AS A INNER JOIN [SELECT EMPLID, Max(EFFSEQ) As LastSeq, Max(EffDt) As LastDate FROM JOB GROUP BY EMPLID
]. AS L ON (A.EFFDT = L.LastDate) AND (A.EMPLID = L.EMPLID)

WHERE (((A.EMPL_STATUS) In ("A","L")) 
  AND ((A.DEPTID) Like "######10*"))[b]
  and A.EFFDT = DateSerial(year(A.EFFDT), month(A.EFFDT),0)
[/b]
ORDER BY A.EMPLID;

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top