现在已经建好表,还没有记录,想写进9条记录的数据进而是100多条,只写第一列,值有规律:
第一列
20030925000001
20030925000002
...
20030925000009
...
20030925000010
20030925000011
...
20030925000128
...
请问SQL Server里如何实现?
declare @i int
set @i=1000
while @i>1
begin
insert into 表 values(convert(char(8),getdate(),112)+right(000000+cast(1000-@i+1 as varchar(6)))
end
declare @a int
set @a=1
while @a<=10000--你要加的最大数
begin
insert tablename(co1) select 20030925+right(000000+cast(@a as varchar),6)
set @a=@a+1
end
create table ai ( i varchar(1000))
declare @n smallint,@m varchar(100)
select @n=1
while @n<你的上限
begin
select @m=convert(varchar(100),@n)
select @m=(case when len(@m)=1 then 00000
when len(@m)=2 then 0000
when len(@m)=3 then 000
end)+@m
insert into ai select convert(char(8),getdate(),112)+@m
select @n=@n+1
end
20030925000001
20030925000002
...
20030925000009
...
20030925000010
20030925000011
...
20030925000128
...