I have a table that contains the current state of employees like below :
SELECT EmployeeId ,OfficeId from EmpCurrent
The output is like below :
EmployeeId OfficeId
54 67
64 57
89 23
And I have another table containing the full history for an employee except for OfficeId which isn't historised (I added the column OfficeId which is NULL to insert from EmpCurrent) :
SELECT EmployeeId ,Func AS [Function],OfficeId,Version from EmpHistory
The output is like below for EmployeeId=54:
EmployeeId Function OfficeId Version
54 Manager NULL 1
54 Director NULL 2
54 HeadOf NULL 3
I want to get the OfficeId from EmpCurrent and insert it in EmpHistory in the last Version(max version) of the each Employee, my output will be like below :
EmployeeId Function OfficeId Version
54 Manager NULL 1
54 Director NULL 2
54 HeadOf 67 3