I previously created this SELECT command in SQL Server, that needs to count how many Employees each Department contains.
This is what I used:
SELECT Departments.Description AS [Department], COUNT(Employees.ID) AS [Employees]
FROM Employees
RIGHT JOIN Departments ON
Employees.DepartmentID = Departments.ID
GROUP BY Departments.Description
And it works fine (also shows the Department, even if there are no Employees).
Now, I want to count only the currently working employees, by the following filter:
WHERE Employees.JobEndDate = null
And I tried doing this:
SELECT Departments.Description AS [Department], COUNT(Employees.ID) AS [Employees]
FROM Employees
RIGHT JOIN Departments ON
Employees.DepartmentID = Departments.ID
WHERE Employees.JobEndDate = NULL
GROUP BY Departments.Description
But now I get no results.
Any idea what I’m doing wrong?
Thanks 🙂
Mitsy.
Testing if a field returned value is
NULLis not performed through equal=sign but withISoperatordoesn’t work, instead write: