0

我想知道是否有人在 SQL 中具有给定初始日期、天数、频率和最终日期的函数来计算下一个匹配的天数和月份?

例如

@initialdate=20130101
@finaldate=20133112
@daynumber=14  --that means every 14
@frecuency=2

然后查询生成下一个日期,如下所示:

 20130114
 20130314
 20130514
 20130714
 20130914
 20131114

如果解决方案是 CTE,则更好,如果在 2 月 28 日至 29 日验证并且天数为 31 时会更好。

这是我正在处理的查询,它即将在给定频率类型、频率和取决于频率类型的发生率的情况下生成日期。

Type of Frec         Frecuency          Ocurrence
DI (Dairy)           1 (Every 1 day)    na
DI (Dairy)           2 (Every 2 day)    na
..
DI (Dairy)           6 (Every 6 day)    na
SE (Weekly)          1 (Every 1 week)   1   (for Monday)
SE (Weekly)          2 (Every 2 weeks)  3   (for Wednesday)
SE (Weekly)          3 (Every 3 weeks)  5   (for Friday)
SE (Weekly)          4 (Every 4 weeks)  2   (for Tuesday)
MD (Monthly by day)  1 (Every 1 month)  1   (for first day of the month)
MD (Monthly by day)  1 (Every 1 month)  2   (for last day of the month)
...
MD (Monthly by day)  11 (Every 11 months) 2   (for last day of the month)
MF (Monthly by date) 1 (Every 1 month)  14   (for every 14 of the month)
...
MF (Monthly by date) 2 (Every 2 months) 30   (for every 30 of the month)
MF (Monthly by date) 3 (Every 3 months) 31   (for every 31 of the month)
4

0 回答 0