当前位置: 代码迷 >> Sql Server >> 怎样知道记录中有那些号漏了?该如何解决
  详细解决方案

怎样知道记录中有那些号漏了?该如何解决

热度:35   发布时间:2016-04-27 15:24:26.0
怎样知道记录中有那些号漏了?
例如:
表A   ,serial   列:
ch001
ch002
ch003
.....
ch099
如果因为某某原因,中间有的单号断开了,怎样写语句就能找到其中的记录呢?

------解决方案--------------------
--try

declare @i int
set @i=1
create table #T(No char(5))

while @i <=99
begin
insert #T select 'ch '+right( '000 '+rtrim(@i), 3)
set @[email protected]+1
end

select B.No from #T as B
where not exists(select 1 from A where serial=B.No)
------解决方案--------------------
感觉上面的方法就是建立一个数值连续的表,然后做比对.
还有别的办法么.
  相关解决方案