I am working with the Datetime column where I am having trouble calculating the Time because of overlapping in time.
This is my sample data
Declare @T table (ID Int, InTime Datetime,OutTime Datetime)
Insert into @T values (1,'2020-08-23 09:26:07.000','2020-08-23 09:57:55.000')
Insert into @T values (1,'2020-08-23 14:09:08.000','2020-08-26 08:13:45.000')
Insert into @T values (1,'2020-08-24 11:14:37.000','2020-08-24 18:07:25.000')
Insert into @T values (1,'2020-08-25 09:19:38.000','2020-08-25 19:19:29.000')
Insert into @T values (1,'2020-08-26 08:13:50.000','2020-08-28 08:39:23.000')
Insert into @T values (1,'2020-08-27 08:42:16.000','2020-08-27 11:38:06.000')
Insert into @T values (1,'2020-08-27 09:51:14.000','2020-08-28 18:23:06.000')
Insert into @T values (1,'2020-08-29 09:51:14.000','2020-08-30 18:23:06.000')
My Expected Output:
+----+-------------------------+--------------------------+
| ID | InTime | OutTime |
+----+-------------------------+--------------------------+
| 1 | 2020-08-23 09:26:07.000 | 2020-08-23 09:57:55.000 |
| 1 | 2020-08-23 14:09:08.000 | 2020-08-26 08:13:45.000 |
| 1 | 2020-08-26 08:13:50.000 | 2020-08-28 08:39:23.000 |
| 1 | 2020-08-29 09:51:14.000 | 2020-08-30 18:23:06.000 |
+----+-------------------------+--------------------------+
If you see the 2nd entry in a table where my Intime is 2020-08-23 14:09:08.000 and outTime is 2020-08-26 08:13:45.000. So if there is any entry in a table between 23 and 26 we should skip that entry. so In out table we need to skip 24th and 25th entry.
Can someone please help me with this query. Any help will be appreciated
I tried this link but couldn't understand the logic Link