更新时间:2023-01-20 11:24:51
一种方法是递归CTE:
One method is a recursive CTE:
with cte as (
select dateadd(day, 1 - day(@startdate), @startdate) as som,
eomonth(@startdate) as eom
union all
select dateadd(month, 1, som), eomonth(dateadd(month, 1, som))
from cte
where dateadd(month, 1, som) < @enddate
)
select *
from cte;
如果要输入月份名称,则可以使用 datename(个月)。
。
If you want the name of the month, then you can use datename(month, som)
.