Something like this for attended days:
Code:
SELECT EmployeeName, COUNT(*) DaysAttended
FROM Attendance
WHERE (Attendance_Date >= @StartDate OR @StartDate IS NULL)
AND (Attendance_Date <= @EndDate OR @EndDate IS NULL)
AND Status = 'P'
GROUP BY EmployeeName
ORDER BY EmployeeName;
or this for all days:
Code:
SELECT EmployeeName, Status, COUNT(*) DaysAttended
FROM Attendance
WHERE (Attendance_Date >= @StartDate OR @StartDate IS NULL)
AND (Attendance_Date <= @EndDate OR @EndDate IS NULL)
GROUP BY EmployeeName, Status
ORDER BY EmployeeName, Status;
You will need to declare the two parameters, @StartDate and @EndDate, for your procedure.
--
Joe (
Microsoft MVP - XML)