如何在SQL中循环日期基于月份和年份。?

时间:2014-12-30 03:57:50

标签: sql stored-procedures

我希望根据月份和年份从开始到结束循环日期。例如

Month is 12 and year is 2014.

01 Dec 2014 
02 Dec 2014 
03 Dec 2014 
.
.

31 Dec 2014 

1 个答案:

答案 0 :(得分:1)

使用Recursive CTE

with CTE
as
(
select N=0
UNION ALL 
select N+1 from CTE where N<30

)select CONVERT( CHAR(12),DATEADD(D,N,CAST('2014-12-01' as DATE)),106)  from CTE