I've gotten my query this far, however if 2 actions happened on a record on the same day - I get 2 results for that record.
Say a person 006 changed locations and got a raise on the same day, they will have EFFSEQ 0 and EFFSEQ 1 for that day - thus giving me 2 records for person 006 in my results. What I want to see is EFFSEQ 1 only (the max one). I think, in order to get that I need to pull MAX(EFFSEQ) from the results showing here, but I'm just not good enough to figure out a 3rd nested query. Can anybody help me with that?
Say a person 006 changed locations and got a raise on the same day, they will have EFFSEQ 0 and EFFSEQ 1 for that day - thus giving me 2 records for person 006 in my results. What I want to see is EFFSEQ 1 only (the max one). I think, in order to get that I need to pull MAX(EFFSEQ) from the results showing here, but I'm just not good enough to figure out a 3rd nested query. Can anybody help me with that?
Code:
SELECT
a.EMPLID,
(CONVERT(CHAR(10),a.[EFFDT],110)) AS EFF_DT,
a.EMPL_STATUS,
a.HR_STATUS,
a.EFFSEQ,
a.EMPL_RCD,
a.DEPTID
FROM PS_JOB a
INNER JOIN
(
SELECT
PS_JOB.EMPLID,
Max((CONVERT(CHAR(10),PS_JOB.[EFFDT],110))) AS Max_EFF_DATE
FROM
PS_JOB
GROUP BY PS_JOB.EMPLID
) b
ON (a.EMPLID=b.EMPLID)
AND (a.EFFDT = b.Max_EFF_DATE)
WHERE a.EMPL_RCD = 0
GROUP BY a.EMPLID, a.EFFDT, a.EMPL_STATUS, a.EFFSEQ, a.HR_STATUS, a.EMPL_RCD, a.DEPTID