I have a table full of start and end dates like
| Start | End |
|---|---|
| 2023-05-19 20:00:00.000 | 2023-05-22 05:30:00.000 |
| 2023-05-22 05:30:00.000 | 2023-05-24 11:30:00.000 |
I would like one select query that returns all of them split into
| Start | End |
|---|---|
| 2023-05-19 20:00:00.000 | 2023-05-19 23:59:59.000 |
| 2023-05-20 00:00:00.000 | 2023-05-20 23:59:59.000 |
| 2023-05-21 00:00:00.000 | 2023-05-21 23:59:59.000 |
| 2023-05-22 00:00:00.000 | 2023-05-22 05:30:00.000 |
I've tried https://stackoverflow.com/a/57142843/22022398 But it does not work when it's more than 1 day
| Start | End |
|---|---|
| 2023-05-19 20:00:00.000 | 2023-05-19 23:59:59.000 |
| 2023-05-22 00:00:00.000 | 2023-05-22 05:30:00.000 |
My SQL server is MSSQL15 so I can't use generate_series()
I've also tried https://stackoverflow.com/a/25911919/22022398 but can't figure out how to implement it for a whole table instead of a single date
23:59:59.000ideally you would use00:00:00ie the beginning of the next day and use exclusive end, see also sqlblog.org/2011/10/19/… Otherwise you will miss one second of data