Hi Team,
Can anyone help on getting below output dynamically based on Start and End Date value
Declare @StartDate datetime,@EndDate Datetime
set @StartDate = '2018-10-01 00:00:00.000'
set @EndDate = '2020-12-31 00:00:00.000'
Requirment : 5 months lag will rolling 12 months value should be repeated for each quarter
output should be :
| Runmonth | ServiceBeginDate | ServiceEndDate |
|---|---|---|
| 201810 | 6/1/2017 | 5/31/2018 |
| 201811 | 6/1/2017 | 5/31/2018 |
| 201812 | 6/1/2017 | 5/31/2018 |
| 201901 | 9/1/2017 | 8/31/2018 |
| 201902 | 9/1/2017 | 8/31/2018 |
| 201903 | 9/1/2017 | 8/31/2018 |
| 201904 | 12/1/2017 | 11/30/2018 |
| 201905 | 12/1/2017 | 11/30/2018 |
| 201906 | 12/1/2017 | 11/30/2018 |
| 201907 | 3/1/2018 | 2/28/2019 |
| 201908 | 3/1/2018 | 2/28/2019 |
| 201909 | 3/1/2018 | 2/28/2019 |
| 201910 | 6/1/2018 | 5/31/2019 |
| 201911 | 6/1/2018 | 5/31/2019 |
| 201912 | 6/1/2018 | 5/31/2019 |
| 202001 | 9/1/2018 | 8/31/2019 |
| 202002 | 9/1/2018 | 8/31/2019 |
| 202003 | 9/1/2018 | 8/31/2019 |
| 202004 | 12/1/2018 | 11/30/2019 |
| 202005 | 12/1/2018 | 11/30/2019 |
| 202006 | 12/1/2018 | 11/30/2019 |
| 202007 | 3/1/2019 | 2/28/2020 |
| 202008 | 3/1/2019 | 2/28/2020 |
| 202009 | 3/1/2019 | 2/28/2020 |
| 202010 | 6/1/2019 | 5/31/2020 |
| 202011 | 6/1/2019 | 5/31/2020 |
| 202012 | 6/1/2019 | 5/31/2020 |