This is a question of different way to run this statement or a way to make it more efficient really.
This statement is meant to name all the staff who will leave the site the soonest, but they staff also have to be on site today.
SELECT
e.EmpName,
cs.SiteName
FROM
Employee e
INNER JOIN
EmployeeAssignment ea
ON
e.EmpId = ea.EmpId
INNER JOIN
CustomerSite cs
ON
ea.CustId = cs.CustId
WHERE
e.EmpId IN
(
SELECT
ea.EmpId
FROM
EmployeeAssignment ea
WHERE
ea.EndDate IN
(
SELECT
MIN(ea.EndDate)
FROM
EmployeeAssignment ea
WHERE
GETDATE() BETWEEN ea.StartDate AND ea.EndDate
GROUP BY
CustId
));
if anyone cna think of a better way to write this please reply thank you 🙂
Try this