You should provide data in a consumable format that we can use to test and validate a solution. Here is an example:
Declare @Attendance Table (
Id int Identity(1,1) Primary Key
, AttDate datetime
, EmpId int
, WorkHrs decimal(3,1)
, ClockedIn char(5)
, ClockedOut char(5)
, HolidayHrs decimal(3,1)
, DayOffHrs decimal(3,1)
, MatHrs decimal(3,1)
, WorkHomeHrs decimal(3,1));
Insert Into @Attendance (AttDate, EmpId, WorkHrs, ClockedIn, ClockedOut, HolidayHrs, DayOffHrs, MatHrs, WorkHomeHrs)
Values ('2021-01-01', 1, 8.3, Null, Null, 8.3, Null, Null, Null)
, ('2021-01-01', 2, 7.3, Null, Null, 7.3, Null, Null, Null)
, ('2021-01-01', 3, 7.3, Null, Null, 7.3, Null, Null, Null)
, ('2021-01-01', 4, 8.3, Null, Null, 8.3, Null, Null, Null)
, ('2021-01-02', 1, 8.3, '09:00', '17:00', Null, Null, Null, Null)
, ('2021-01-02', 2, 7.3, '09:30', '17:30', Null, Null, Null, Null)
, ('2021-01-02', 3, 7.3, Null, Null, Null, 7.3, Null, Null)
, ('2021-01-02', 4, 8.3, '17:00', Null, Null, Null, Null, Null)
, ('2021-01-03', 1, 8.3, '08:00', Null, Null, Null, Null, Null)
, ('2021-01-03', 2, 7.3, Null, Null, Null, Null, 7.3, Null)
, ('2021-01-03', 3, 7.3, Null, Null, Null, Null, Null, Null)
, ('2021-01-03', 4, 8.3, '09:30', '12:00', Null, Null, Null, Null)
, ('2021-01-03', 1, 8.3, '17:30', Null, Null, Null, Null, Null)
, ('2021-01-03', 2, 7.3, '08:30', Null, Null, Null, Null, Null)
, ('2021-01-03', 3, 7.3, '08:30', Null, Null, Null, Null, Null)
, ('2021-01-03', 4, 8.3, Null, Null, Null, Null, Null, 8.3);
Your description does not match the desired results...
EmpId = 1, AttDate = 2021-01-01: HolidayHrs are equal to WorkHrs but that row is not included in your desired results. Based on your rules - all rows should be returned.
Can you explain your desired results further?