Click here to Skip to main content
15,897,519 members
Articles / Database Development / SQL Server

Spilt DateTime Ranges in SQL Server

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
1 Jul 2023CPOL2 min read 8.5K   18   2  
Split date time ranges into days or possibly other ranges using CTE in SQL Server
This code snippet demonstrates how to convert a date range into a set of rows in SQL, including handling overlapping date ranges and splitting ranges into day-wise records. It provides two examples: one for splitting date ranges into individual days and another for splitting ranges into overlapping or related ranges. The code includes recursive CTEs and joins to achieve the desired results efficiently.

Views

Daily Counts

Downloads

Weekly Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Bangladesh Bangladesh
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions