I am very new to SQL Server. I am trying to split time in time out records that fall between night shifts from a employee shifts table but I am having a difficult time doing so. Night Shift runs from 10pm to 7am.
Example below might help make things clearer.
E.g
EmployeeId InTime OutTime
---------- ----------------------- -----------------------
1 2018-08-10 21:00:00.000 2018-08-11 09:00:00.000
Desired Output
EmployeeId InTime OutTime Type
---------- ----------------------- ----------------------- -------
1 2018-08-10 21:00:00.000 2018-08-10 22:00:00.000 day
1 2018-08-10 22:00:00.000 2018-08-11 07:00:00.000 night
1 2018-08-11 07:00:00.000 2018-08-11 09:00:00.000 day
code for current table:
DECLARE @tbl TABLE
(
EmployeeId INT,
InTime DATETIME,
OutTime DATETIME
)
INSERT INTO @tbl(Employee_Id,Shift_Start,Shift_end) VALUES (1,'2018-08-10 21:00:00.000','2018-08-11 09:00:00.000')
9 pm to 11 pm
? – Biju jose Aug 19 '18 at 7:30