last day (19 days later) » 

04:34
-1
Q: Create Date Spans from Contiguous and Non-Contiguous Date Spans

JOSH WI am trying to create a query where I can take date spans and return the month, day and year for the BEG_DT for each year between the BEG_DT and END_DT while maintaining the month and day of the 'BEG_DT'. When a date span goes into the future by more than one year, I need it to limit the results ...

Could you please update your post's tags to include the database system and version?
I made a fiddle here using SQL Server 2014 as the server (syntax leads me to believe that it's SQL Server) - I've split the data into 3 groups - could you explain group by group what you want and why? Also, in future, could you please provide your data both as a (tested) fiddle and here - help us to help you, the more information we have, the better we can answer. Check out my profile for a few tips on how to ask good questions.
@Vérace Thank you for your feedback. I have updated the information to try and be more specific.
I've started to reformat - but I'm afraid of losing information. Can you please remove the ALL CAPS - and format the sections to make it more legible? Break it down - group by group, record by record... The clearer your explanation, the better chance we have of resolving your issue!
And why do we see no trace of this: ('32198498','AMD00003','2020-10-01','2100-09-30','12') in your desired result?
@Vérace I have updated the explanation to lower case and also updated the expected results to more easily differentiate between the different groups and plan IDs. I also updated the results for Group ID 32198498. Thank you again for your help and feedback.
04:34
How does this (('32198498','AMD00002','2020-10-01','2022-09-30','12')) turn into 4 records in the result set?
@Vérace That was an error. I have updated the results. Thank you.
I'll take a look tomorrow!
There are errors in your data: Input: '75491773','AMT00004' - there is no 31st of June. Output: 82551399, AMT00003, the second date should be 2021? '32198498','AMD00003' there should be 3 output records - or else I haven't/can't understand what's going on! Please tidy up the question - try inserting your desired result into a table using suitable UNIQUE constraints (and/or PKs...).
Please go here and explain clearly line by line why record x is generated and expand on your stuff above... Requirements are unclear at the moment...
@Vérace unfortunately 'Fiddle' doesn't give me to option to save my updates to what you started. Here are the answers: Line 24(32198498) the max date should be less than one year in the future from the run date. Line 52 (82551399) the 2022 date should be removed
It will give you the opportunity - run the new fiddle and notice the SHA252 - or whatever it is - in the link change - this is the new permalink to what you have added!
@Vérace I created a new fiddle here to try and answer your questions dbfiddle.uk/…
04:34
So for every date range of [BEG_DT, END_DT], you want to generate a list of dates which: 1) start at BEG_DT, 2) are one year apart, 3) do not exceed END_DT, and 4) do not exceed the day of one year from the current day. Is that summary correct and does it capture all your requirements?
@AndriyM yes, that is correct. I would add a fifth point, that we would only do this for plans where the 'PLAN_LENGTH' is equal to 12.
What should be done about the plans whose PLAN_LENGTH is not equal to 12?
Let me try again. For every date range of [BEG_DT, END_DT] with an associated PLAN_LENGTH, you want to generate a list of dates which: 1) start at BEG_DT, 2) are PLAN_LENGTH months apart, 3) do not exceed END_DT, and 4) do not exceed the day that is PLAN_LENGTH months from the current day. Would that be closer to what you have in mind?
 
16 hours later…
20:41
@AndriyM If a row does not have a 'PLAN_LENGTH' equal to twelve it should be passed through as it is represented in the data. Your new synopsis is correct. Thank you!

  last day (19 days later) »