If not exists(select 1 from 表名 where 编号='编号') insert into 表名 (code) values ('编号')
declare @i int set @i=1 while @i<=1000 begin insert into 表名(code) select @i where not exists(select 1 from 表名 where code=@i) set @i=@i+1 end
DECLARE @i int DECLARE @j int set @i=1 set @j=1000 insert into tb(Id) select b.number from master..spt_values b where b.type='P' and b.number>=@i and b.number<=@j and NOT Exists(select 1 from tb t where b.number=t.Id)
insert into 表名 (code) values ('编号')
set @i=1
while @i<=1000
begin
insert into 表名(code)
select @i
where not exists(select 1 from 表名 where code=@i)
set @i=@i+1
end
DECLARE @i int
DECLARE @j int
set @i=1
set @j=1000
insert into tb(Id)
select b.number
from master..spt_values b where b.type='P'
and b.number>=@i and b.number<=@j
and NOT Exists(select 1 from tb t where b.number=t.Id)