create table table1(the_date datetime)
declare @i int
select @i=datediff(day,'2001-01-01',getdate())
while (@i>0)
begin
insert into table1 (the_date) select dateadd(day,@i,'2001-01-01')
select @i=@i-1
end
declare @i int
select @i=datediff(day,'2001-01-01',getdate())
while (@i>0)
begin
insert into table1 (the_date) select dateadd(day,@i,'2001-01-01')
select @i=@i-1
end
set @b = '2001-1-1'
while @b <= getdate()
begin
insert into yourtable (the_date, the_day, the_month) values
(@b, day(@b), month(@b))
set @b = dateadd(day, @b, 1)
end
select * from yourtable
set @b = '2001-1-1'
while @b <= getdate()
begin
insert into yourtable (the_date, the_day, the_month) values
(@b, day(@b), month(@b))
set @b = dateadd(day, 1, @b)
end
select * from yourtable
select top 8000 identity(int,0,1) as N into numtab from
(select top 100 id=1 from sysobjects) as a,
(select top 100 id=1 from sysobjects) as b,
(select top 100 id=1 from sysobjects) as c2,
insert into 表(the_date,the_day,the_month)
select n+cast('2001-01-01' as datetime)
,day(n+cast('2001-01-01' as datetime))
,month(n+cast('2001-01-01' as datetime))
from Numtab
where n+cast('2001-01-01' as datetime)>getdate()