select * from tab where rec_no no in (1.2.3.4.5.6)
CREATE TABLE #(ID INT NOT NULL IDENTITY(1,1),A VARCHAR(10))INSERT INTO @(A) SELECT TOP 5000 '1' FROM TABLESELECT ID FROM # A LEFT JOIN TBALE B ON A.ID=B.ID WHERE B.ID IS NULL
select * from tab where rec_no no in (1,2,3,4,5,6)
select top 5000 identity(int,1,1) id into #a from sysobjects a,sysobjects bselect * from #a where id not in (select id from 你的表) and id<(select max(id) 你的表)
假设字段是a
select isnull(min(a+1),1) from (select a from 原来表 union select 0 from 原来表) t where not exists (select 1 from 原来表 where t.a+1 =原来表.a)
“缺少的一個數”比较好办:select 编号+1 as 缺少的编号 from 表 as a where not exists(select * from 表 where 编号=a.编号+1) 否则: select 编号,(select min(编号) from 表 where 编号>a.编号) from 表 as a where not exists(select * from 表 where 编号=a.编号+1)
SELECT TOP 5000 '1' FROM TABLESELECT ID
FROM # A LEFT JOIN TBALE B
ON A.ID=B.ID
WHERE B.ID IS NULL
select isnull(min(a+1),1) from (select a from 原来表 union select 0 from 原来表) t where not exists (select 1 from 原来表 where t.a+1 =原来表.a)
编号=a.编号+1)
否则:
select 编号,(select min(编号) from 表 where 编号>a.编号) from 表 as a
where not exists(select * from 表 where 编号=a.编号+1)