this is a table for attendance logs:
CREATE TABLE [dbo].[DeviceLogs] (
[DeviceLogId] INT NOT NULL,
[UserId] NVARCHAR (50) NOT NULL,
[LogDate] DATETIME NOT NULL,
);
this is my employee table:
CREATE TABLE [dbo].[Employees] (
[EmployeeId] INT IDENTITY (1, 1) NOT NULL,
[EmployeeName] NVARCHAR (50) NULL,
[UserId] NVARCHAR (50) NOT NULL,
[Gender] NVARCHAR (255) NULL,
[DepartmentId] NVARCHAR (255) NULL,
[Designation] NVARCHAR (255) NULL,
[CategoryId] INT NULL,
[DOJ] DATETIME NULL,
[DOR] DATETIME NULL,
[Status] NVARCHAR (255) NULL,
[DOB] DATETIME NULL,
);
We will insert attendance logs in the first table.
Now i want to calculate attendance for each employee in each day.
SELECT [userid] AS identit,
CONVERT(VARCHAR, userid),
Min(logdate) AS lowtime,
Max(logdate) AS hightime,
CONVERT(VARCHAR, Max(logdate) - Min(logdate), 108) AS dur,
CASE
WHEN CONVERT(VARCHAR, Max(logdate) - Min(logdate), 108) IS NOT NULL
THEN
'present'
ELSE 'Absent'
END AS Status
FROM [dbo].[devicelogs]
GROUP BY [userid]
ORDER BY userid DESC
This is the MS SQl query which i'm using. But it is giving me result only if the person has attendance logs.
I want to calculate attendance even in the person is absent. I want it to repeat it for everyday.
Please help me here.