sql 循环某段时间的每一天

时间:2023-11-28 19:04:56

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