日期:2014-05-17 浏览次数:20581 次
declare @year int =2008
declare @day int=26;
select number
,t.yearnumber*100+number as MonthNumber
,dateadd(d,1,dateadd(month,-1,convert(date,convert(varchar(20), t.yearnumber*10000+number*100+daynumber-1)))) startDate
,convert(date,convert(varchar(20), t.yearnumber*10000+number*100+daynumber-1)) endDate
from master..spt_values sv
cross join (select @year yearnumber,@day daynumber) as t
where [type]='p'
and number>0
and number<=12
select number
,t.yearnumber*100+number as MonthNumber
,convert(date,convert(varchar(20), t.yearnumber*10000+number*100+1)) startDate
,dateadd(d,-1,dateadd(month,1,convert(date,convert(varchar(20), t.yearnumber*10000+number*100+1)))) endDate
from master..spt_values sv
cross join (select @year yearnumber,@day daynumber) as t
where [type]='p'
and number>0
and number<=12