I have a table with activities. The columns are: activityId, nextDate, frequency. The frequency is in months. I need a query that will generate all the dates at which the activity will take place based on frequency (in months). I am using DB2.
Activities table:
| activityId | nextDate | frequency |
|---|---|---|
| 1 | 03/01/2024 | 2 |
Giving parameter: 12/31/2024
Output needed:
| activityId | date |
|---|---|
| 1 | 03/01/2024 |
| 1 | 05/01/2024 |
| 1 | 07/01/2024 |
| 1 | 09/01/2024 |
| 1 | 11/01/2024 |
You can do it with a recursive CTE
fiddle