过滤出两个日期间的所有日期
参考:
declare @t1 datetime,@t2 datetime,@t3 datetime
set @t1 = '2010-01-01'
set @t2 = '2010-12-31'
set @t3 = @t1
while datediff(d,@t3,@t2) >=0
begin
select @t3 = dateadd(d,1,@t3)
print convert(varchar(10),@t3,120)
end
实际应用:
declare @djh char(12)
declare @t1 datetime,@t2 datetime,@t3 datetime,@gh char(4)
set @djh='E180919 0005'
select @t1=e_d1,@t2=e_d2,@gh=e_unum from e where [email protected]
set @[email protected]
set @[email protected]
set @t3 = @t1
while datediff(d,@t3,@t2) >=0
begin
select @t3 = dateadd(d,1,@t3)
insert into xzhr_el (gh,dd,lx,djh)values(@gh,convert(varchar(10),@t3,120),'请假',@djh)
end
select * from xzhr_el