日期:2014-05-17 浏览次数:20660 次
declare @i int,@sdt varchar(10),@edt varchar(10)
set @i=1
set @sdt=datename(yy,getdate())+'-'+cast(@i as varchar)+'-01'
set @edt=convert(varchar,dateadd(m,1,@sdt),23)
--年限你自己控制一下吧
select @sdt,@edt
;with cte as(
select dateadd(day,number,@sdt) time
from master..spt_values where type='P' and number<31
)select * from cte where time<@edt
/*
2013-01-01 00:00:00.000
2013-01-02 00:00:00.000
2013-01-03 00:00:00.000
2013-01-04 00:00:00.000
2013-01-05 00:00:00.000
2013-01-06 00:00:00.000
2013-01-07 00:00:00.000
2013-01-08 00:00:00.000
2013-01-09 00:00:00.000
2013-01-10 00:00:00.000
2013-01-11 00:00:00.000
2013-01-12 00:00:00.000
2013-01-13 00:00:00.000
2013-01-14 00:00:00.000
2013-01-15 00:00:00.000
2013-01-16 00:00:00.000
2013-01-17 00:00:00.000
2013-01-18 00:00:00.000
2013-01-19 00:00:00.000
2013-01-20 00:00:00.000
2013-01-21 00:00:00.000
2013-01-22 00:00:00.000
2013-01-23 00:00:00.000
2013-01-24 00:00:00.000
2013-01-25 00:00:00.000
2013-01-26 00:00:00.000
2013-01-27 00:00:00.000
2013-01-28 00:00:00.000
2013-01-29 00:00:00.000
2013-01-30 00:00:00.000
2013-01-31 00:00:00.000
*/