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;
If you want the name of the month, then you can use datename(month, som)
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…