select
min(b.ID) + 1
from
(select
a.ID
from
表 a
where
not exists(select 1 from 表 where ID = a.ID+1)
union
select
0
from
表
where
not exists(select 1 from 表 where ID = 1) b
min(b.ID) + 1
from
(select
a.ID
from
表 a
where
not exists(select 1 from 表 where ID = a.ID+1)
union
select
0
from
表
where
not exists(select 1 from 表 where ID = 1) b
min(b.ID) + 1
from
(select
a.ID
from
表 a
where
not exists(select 1 from 表 where ID = a.ID+1)
union
select
0
from
表
where
not exists(select 1 from 表 where ID = 1) b
select id,identity(int,1,1) as ident into #gwl from testgwl order by id
select min(ident) from #gwl where id<>ident