Months between two dates

前端 未结 8 2101
悲&欢浪女
悲&欢浪女 2020-11-28 07:35

Is it possible to get month names between two dates in SQl

ie, 2011-05-01 And 2011-08-01 are the inputs I just w

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 08:03

        declare @start DATE = '2011-05-30'
        declare @end DATE = '2011-06-10' 
       ;with months (date)
        AS
        (
            SELECT @start
            UNION ALL
            SELECT DATEADD(month,1,date)
            from months
            where DATEADD(month,1,date)<= DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@end)+1,0))
        )
        select Datename(month,date) from months
    

提交回复
热议问题