Calculate start date of almost equal periods
问题 SQL Server CREATE TABLE [TABLE_1] ( PLAN_NR decimal(28,6) NULL, START_DATE datetime NULL, MAX_PERIODS decimal(28,6) NULL, ); INSERT INTO TABLE_1 (PLAN_NR, START_DATE, MAX_PERIODS) VALUES (1, '2020-05-01', 8), (2, '2020-08-01', 8); SQL - FIDDLE I've got a table with the columns PLAN_NR , START_DATE and MAX_PERIODS . Each period is exactly 7 days long, unless the period contains a month end. Then the period should be divided into a range before the end of the month up to and including the last