select a from #tab1 x where not exists(select 1 from #tab1 where a = x.a + 1)

解决方案 »

  1.   

    上面的不对,看这个select min(字段1) from table1 x 
    where not exists(select 1 from table1 where 字段1 = x.字段1 + 1)
      

  2.   

    select min(字段1) from table1 tem where not exists(select 1 from table1 where 字段1-1=tem.字段1)
      

  3.   

    declare @ table(a int)
    insert @ values(2)
    insert @ values(1)
    insert @ values(7)
    insert @ values(8)select min(a) from @ tem where not exists(select 1 from @ where a-1=tem.a)
      

  4.   

    select 1    1是什么东西呀,是数字1 还是字段名L ??
      

  5.   

    create function getnotcontinue (@str varchar(40))
    returns int
    as
    begin
      Declare @return1 int
      Declare @i int
      set @i=1
      while (@i < 5)
      begin
        if (cast(substring(@str,@i*2 - 1,1) as int) + 1) <> cast(substring(@str,(@i+1)*2 - 1,1) as int)
        begin
          set @return1=substring(@str,@i*2 -1,1)
          break
        end
        set @i=@i + 1
      end
      return @return1
    endselect 字段1,dbo.getnotcontinue(字段1) from table1