显示出两个时间段的日期
例如:2013-10-01,2013-10-17
显示结果为:
日期 年月
2013-10-012013-10
2013-10-022013-10
2013-10-032013-10
2013-10-042013-10
2013-10-052013-10
2013-10-062013-10
2013-10-072013-10
2013-10-082013-10
2013-10-092013-10
2013-10-102013-10
2013-10-112013-10
2013-10-122013-10
2013-10-132013-10
2013-10-142013-10
2013-10-152013-10
2013-10-162013-10
2013-10-172013-10
[解决办法]
declare @sd datetime,@ed datetime
select @sd='2013-10-01',@ed='2013-10-17'
select CONVERT(varchar(10),dt,120) as 日期,CONVERT(varchar(7),dt,120) as 年月
from(
select
dateadd(dd,number,@sd) as dt
from master..spt_values
where type='P' and dateadd(dd,number,@sd)<=@ed
) t