I am trying to display reports in which based on employee code, I have to display how many days he/she presents on monthly basis.
Emp_Code Date Attendance
1001 2023-01-01 1
1001 2023-01-02 1
1001 2023-01-03 1
1001 2023-01-04 1
1001 2023-01-05 0
1001 2023-01-06 0
1001 2023-01-07 1
1001 2023-01-08 1
.
.
.
1002 2023-01-01 1
1002 2023-01-02 0
1002 2023-01-03 1
.
.
.
1003 2023-01-01 1
Attendance is a boolean column (0,1) 0 - This means the employee is absent, and 1 Means the employee is present on that day.
SQL query to Calculate monthly report as follow:
1001 Jan 2
1001 Feb 1
1001 Mar 0
1001 Apr 2
I wrote the query but shows me the number of present days, can anyone help me to correct it plz?
SELECT Emp_Code,MAX(DATENAME(MM,Date)) AS MonthWisePresentOrAbsent, COUNT(1) AS "DaysAbsent"
FROM tblEmployee GROUP BY MONTH(Date),Emp_Code;
Edit Question 1 it is a simple concept like every day in January month, 1 to 25 days if I am present then the last column contains the 1 and for 26 to 31 it contains 0.