Check it out!
Sample table and Data
CREATE TABLE Employeement
(
EmployeementID INT IDENTITY(1,1),
EmpID INT,
JOBTitle VARCHAR(100),
StartDate DATETIME,
EndDate DATETIME)
GO
INSERT Employeement(EmpID,JOBTitle,StartDate,EndDate) VALUES(1001,'SQL Developer','2000-01-01','2004-04-10')
INSERT Employeement(EmpID,JOBTitle,StartDate,EndDate) VALUES(1001,'SQL Junion DBA','2004-04-11','2006-05-11')
INSERT Employeement(EmpID,JOBTitle,StartDate,EndDate) VALUES(1001,'SQL DBA','2006-05-12','2011-04-10')
INSERT Employeement(EmpID,JOBTitle,StartDate,EndDate) VALUES(1001,'SQL Senior DBA','2011-04-11','2012-09-15')
GO
INSERT Employeement(EmpID,JOBTitle,StartDate,EndDate) VALUES(1002,'Developer','2000-11-11','2003-04-24')
INSERT Employeement(EmpID,JOBTitle,StartDate,EndDate) VALUES(1002,'Application Developer','2003-04-25','2006-05-11')
INSERT Employeement(EmpID,JOBTitle,StartDate,EndDate) VALUES(1002,'Senior Application Developer','2006-05-12','2011-08-11')
GO
To get MAX or Latest JOBtitle info., of each employee
;WITH LatestTitle
AS
(
SELECT ROW_NUMBER() OVER(PARTITION BY EmpID ORDER BY StartDate DESC) [Req],EmployeementID FROM Employeement
)
SELECT E.* FROM Employeement E JOIN LatestTitle LT ON (E.EmployeementID = LT.EmployeementID)
WHERE LT.Req =1
GO
Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions
Ramakrishna188, if this helps please login to Mark As Answer. | Alert Moderator