sql 循环某段时间的每一天

create table #t1
(
日期 datetime
)


declare @stime datetime;
declare @etime datetime
set @stime ='2015-01-01'
set @etime='2015-02-01'
insert into #t1 (日期)
select @stime

while @stime<DATEADD(DAY,-1,@etime)
begin
insert into #t1 (日期)
select DATEADD(DAY,1,@stime)
set @stime=DATEADD(DAY,1,@stime)
end

truncate table #t1

你可能感兴趣的:(sql)