I can get FirstIn - LastOut out of Day shift employee using min and max:
select
UserId,
[date],
min(convert(char(5), [Login], 108)) as FirstIN,
max(convert(char(5), LogOut,108)) as LastOUT
from Employee
group by UserId, [date]
But I cannot do for Night Shift employee, like 5:30 Pm to next day Morning 2:30 am. At the same day (Next day) they will come again on 5:30 pm.
Shift Table
UserID ShiftName Start End
2267 Night Shift-1 17:30 02:30
Employee Table
UserID LogIn LogOut LogDate
2267 2016-01-04 20:52:08.000 2016-01-04 22:09:22.000 2016-01-04 00:00:00.000
2267 2016-01-04 23:00:07.000 2016-01-04 23:00:07.000 2016-01-04 00:00:00.000
2267 2016-01-05 00:35:46.000 2016-01-05 00:35:46.000 2016-01-05 00:00:00.000
2267 2016-01-05 01:02:31.000 2016-01-05 03:57:16.000 2016-01-05 00:00:00.000
2267 2016-01-05 18:43:50.000 2016-01-05 19:05:04.000 2016-01-05 00:00:00.000
2267 2016-01-05 19:10:20.000 2016-01-05 22:26:00.000 2016-01-05 00:00:00.000
2267 2016-01-05 23:27:24.000 2016-01-05 23:27:24.000 2016-01-05 00:00:00.000
2267 2016-01-06 03:45:16.000 2016-01-06 03:45:16.000 2016-01-06 00:00:00.000
Desired output
EmpId date FirstIN LastOUT
2267 2016-01-04 20:52 03:57
2267 2016-01-05 18:43 03:45