select top 1 id from 表 a
where not exists(select 1 from 表 where id = a.id+1)
order by id
where not exists(select 1 from 表 where id = a.id+1)
order by id
解决方案 »
- 一个关于同步两个表的数据的问题
- 急急急急急!!请问如何将文本文档导入到SQLSEVER2000中?具体要求如下:
- SQL SERVER 2000 升级至 2008 后发现的一个问题
- SQL 分组查询
- 请推荐用什么数据库软件,谢谢!
- 关于delete触发器的问题
- exists
- 在XP Pro下怎么才能装上SQL Server 2000的服务器端?在线等。。。谢谢
- 很奇怪,表中主索引字段Ecn_00类型为int,标识:是(不用于复制),标识种子:1,标识递增量:1,新增数据时出错!
- 一个古老的问题???
- 存储过程中参数的问题。(解决后马上结贴给分!)
- 怎么用SQL Server 2000 Analysis Service做一个数据仓库原型?急急急急急急
declare @t table(id int)
insert @t select 2
union all select 3
union all select 5--求缺少的最小id
select min(id)+1
from(
select id=0 union all select id from @t
)a where not exists(
select * from @t where id=a.id+1)--结果: 1
declare @id intinsert into @tb select 1 union select 2 union select 4 union select 7
select top 1 @id=[id]+1 from @tb where (id+1) not in (select id from @tb) order by [id]select @id
from (select id=0 union all select id from TEST) a
where not exists(
select * from TEST where id=a.id+1)