UPDATE [dbo].[REF_SQLFIELDS] SET [Code]=N'SELECT TOP 1 CAST(Emp.EmployeeId as int)
FROM DT_EMPLOYEE Emp
INNER JOIN LNK_PERSON_ADDRESS LPA
ON LPA.Right_Join = RT.Entity_Id
INNER JOIN LNK_EMPLOYEE_PERSON LEP
ON LPA.Left_Join = LEP.Right_Join
AND Emp.Entity_Id = LEP.Left_Join
AND [PIT] BETWEEN Emp.Entity_Start_Date AND ISNULL(Emp.Entity_End_Date, ''31 dec 2499'')
ORDER BY Emp.Entity_Start_Date DESC' WHERE [Table_Name] = N'DT_ADDRESS' AND [Field_Name] = N'EmpRef' AND [CustomisationID] = 0
UPDATE [dbo].[REF_SQLFIELDS] SET [Code]=N'SELECT TOP 1 CAST(Emp.EmployeeId as nvarchar)
FROM DT_EMPLOYEE Emp
INNER JOIN LNK_PERSON_ADDRESS LPA
ON LPA.Right_Join = RT.Entity_Id
INNER JOIN LNK_EMPLOYEE_PERSON LEP
ON LPA.Left_Join = LEP.Right_Join
AND Emp.Entity_Id = LEP.Left_Join
AND [PIT] BETWEEN Emp.Entity_Start_Date AND ISNULL(Emp.Entity_End_Date, ''31 dec 2499'')
ORDER BY Emp.Entity_Start_Date DESC' WHERE [Table_Name] = N'DT_ADDRESS' AND [Field_Name] = N'EmpRef' AND [CustomisationID] = 6

