Skip to content
Advertisement

Splitting up events that occur over the day boundary

I have a table of events with a start time and an end time, with some events that have a start time before midnight and an end time after midnight. I’d like to produce output that splits up these events at the midnight barrier so they can be counted toward their respective date.

The above table could be produced by the query:

My desired output will split up the events that span multiple days at midnight:

Any help would be greatly appreciated. Ideally I’d like to produce this without functions or the creation of new tables.

Note that I’m using SQL Server 2016

Advertisement

Answer

Using table of numbers

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement