select a from YouTable where convert(int,a)in(1,2,3,4,5,6,7,8,9,10)

解决方案 »

  1.   

    1,建序数表
    select top 8000 identity(int,1,1) as N into numtab from 
    (select top 100 id=1  from sysobjects) as a,
    (select top 100 id=1  from sysobjects) as b,
    (select top 100 id=1  from sysobjects) as c
    2,
    select a.* from numtab a left join 你的表 b on a.n=cast(b.a as int)
    where a.n<=(select cast(max(a) as int) from 你的表) and a.n>=(select cast(min(a) as int) from 你的表) and b.a is null结果
    ----
    5
    9
      

  2.   

    Select right('0000'+convert(varchar(2),a),4)
      from 表 where right('0000'+convert(varchar(2),a),4) not in (Select a from 表)
    and right('0000'+convert(varchar(2),a),4) <> (select max(a) from 表)
      

  3.   

    select a from YouTable where convert(int,a) not in(1,2,3,4,5,6,7,8,9,10)
      

  4.   

    declare @countx int
    declare @i int 
    declare @str_row
    select max(a) into @countx from a
    for @i=1 to @countx
       select a from table where a=right(10000+@i,4)
       if @@rowcunt<1 
          @str_row=@str_row+@i+','
    next
    select @str_row