Break into multiple rows based on date range of a single row
URL: https://stackoverflow.com/questions/43100103/break-into-multiple-rows-based-on-date-range-of-a-single-row Break into multiple rows based on date range of a single row You can use a Calendar or dates table for this sort of thing. For only 152kb in memory, you can have 30 years of dates in a table with this: /* dates table */ declare @ fromdate date = '20000101' ; declare @ years int = 30 ; /* 30 years, 19 used data pages ~152kb in memory, ~264kb on disk */ ; with n as ( select n from ( values ( 0 ),( 1 ),( 2 ),( 3 ),( 4 ),( 5 ),( 6 ),( 7 ),( 8 ),( 9 )) t ( n )) select top ( datediff ( day , @ fromdate , dateadd ( year ,@ years ,@ fromdate ))) [ Date ]= convert ( date , dateadd ( day , row_number () over ( order by ( select 1 )) -1 ,@ fromdate )) into dbo . Dates from n as deka cross join n as hecto cross join n as kilo cross join n as tenK cross join n as hundredK order by [ Date ]; create ...