日期:2014-05-18 浏览次数:20571 次
insert into atable select date,getdate() from table where date between '2011-10-01' and '2011-10-31'
------解决方案--------------------
insert into atable select DATEADD(DAY,number,'2011-10-05'),getdate() from Table1 ,master..spt_values where type='p' and number<DATEDIFF(DAY,'2011-10-01','2011-10-05')
------解决方案--------------------
--功能:找出在2个日期之间的日期 --startdate:2009年9月15日 endDate:2009年10月3日 declare @startdate datetime,@enddate datetime set @startdate='2009-08-30' set @enddate='2009-09-05' select convert(varchar(10),dateadd(day,number,@startdate),120) from master..spt_values where datediff(day,dateadd(day,number,@startdate), @enddate)>=0 and number>0 and type='p' /*---------- 2009-08-31 2009-09-01 2009-09-02 2009-09-03 2009-09-04 2009-09-05 (6 行受影响) /*
------解决方案--------------------
找它的开始时间和结束时间即可:
declare @startdate datetime,@enddate datetime
set @startdate='2010-10-01'
set @enddate='2010-10-05'
while @startdate<=@enddate
begin
insert into atable
select @startdate,@enddate from table where date=@startdate
set @startdate=dateadd(day,1,@startdate)
end