求一条关于日期的循环语句
要求每天执行相同语句能独自进行一个小循环,然后多天的循环出来可以把结果显示在同一张表中
[解决办法]
declare @start_date varchar(10)
declare @end_date varchar(10)
set @start_date = '2013-10-01'
set @end_date = '2013-11-11'
select dateadd(day,number,@start_date) as biz_date
from master..spt_values t
where t.type ='P'
and dateadd(day,number,@start_date) <= @end_date
/*
biz_date
2013-10-01 00:00:00.000
2013-10-02 00:00:00.000
2013-10-03 00:00:00.000
2013-10-04 00:00:00.000
2013-10-05 00:00:00.000
2013-10-06 00:00:00.000
2013-10-07 00:00:00.000
2013-10-08 00:00:00.000
2013-10-09 00:00:00.000
2013-10-10 00:00:00.000
2013-10-11 00:00:00.000
2013-10-12 00:00:00.000
2013-10-13 00:00:00.000
2013-10-14 00:00:00.000
2013-10-15 00:00:00.000
2013-10-16 00:00:00.000
2013-10-17 00:00:00.000
2013-10-18 00:00:00.000
2013-10-19 00:00:00.000
2013-10-20 00:00:00.000
2013-10-21 00:00:00.000
2013-10-22 00:00:00.000
2013-10-23 00:00:00.000
2013-10-24 00:00:00.000
2013-10-25 00:00:00.000
2013-10-26 00:00:00.000
2013-10-27 00:00:00.000
2013-10-28 00:00:00.000
2013-10-29 00:00:00.000
2013-10-30 00:00:00.000
2013-10-31 00:00:00.000
2013-11-01 00:00:00.000
2013-11-02 00:00:00.000
2013-11-03 00:00:00.000
2013-11-04 00:00:00.000
2013-11-05 00:00:00.000
2013-11-06 00:00:00.000
2013-11-07 00:00:00.000
2013-11-08 00:00:00.000
2013-11-09 00:00:00.000
2013-11-10 00:00:00.000
2013-11-11 00:00:00.000
*/