测试数据
--------
create table #test( id varchar(5) primary key)
insert into #test
select 'b0001'
union all
select 'b0002'
union all
select 'b0003'
union all
select 'b0011'
SQL语句
----------
declare @t table (id int identity(1,1),c varchar(5))
insert into @t(c)
select top 9999 '0' from sysobjects a,syscolumns b
update @t set c='b'+right('0000'+convert(varchar(4),id),4)
select * from @t where c not in (select id from #test) and c<=(select max(id) from #test)
结果
-------
id c
----------- -----
4 b0004
5 b0005
6 b0006
7 b0007
8 b0008
9 b0009
10 b0010