日期:2014-05-18  浏览次数:20460 次

插入递增的数据
我想往数据库插入日期递增的数据,如下,请问insert语句该如何写?谢谢~~~
id       riqi
1         2007-1-1
2         2007-1-2
.....
*         2007-2-2

------解决方案--------------------
create table ta (id int identity(1,1), riqi datetime)

declare @date datetime
set @date= '2000-01-01 '
while 10> (select isnull(max(id),0) from ta)
begin
insert ta values(@date)
set @date=@date+1
end

select * from ta

id riqi
----------- -----------------------
1 2000-01-01 00:00:00.000
2 2000-01-02 00:00:00.000
3 2000-01-03 00:00:00.000
4 2000-01-04 00:00:00.000
5 2000-01-05 00:00:00.000
6 2000-01-06 00:00:00.000
7 2000-01-07 00:00:00.000
8 2000-01-08 00:00:00.000
9 2000-01-09 00:00:00.000
10 2000-01-10 00:00:00.000

(10 行受影响)