select id 
from a
where convert(varchar(50),id) not in ('1,2,3')

解决方案 »

  1.   

    select id 
    from a
    where convert(varchar(50),id) not in ('1','2','3')
      

  2.   

    楼上的不对吧, 我要的是3啊 select id 
    from a
     那里有3
      

  3.   

    declare @idstr varchar(8000),@sql varchar(8000)
    set @idstr = '1,2,3'
    create table #t(id int)
    set @sql='insert #t select '+replace(@idstr,',',' s union all select ')
    exec(@sql)
    --@idstr中存在而a表中不存在的id
    select * from #t where not exists(select * from a where id=#t.id)
    --a表中存在而@idstr中不存在的id
    select * from a where not exists(select * from #t where id=a.id)
    drop table #t
      

  4.   

    declare @a varchar(50)
    select @a=id from a
    set idstr=replace(idstr,@a,'')
      

  5.   

    将idstr中每个值处理成一个临时表中的字段的值;再用select语句处理。
      

  6.   

    create table #A(id int)
    insert into  #A select 1
    insert into  #A select 2set rowcount 1000
    select identity(int,1,1) as nid into #t from sysobjects
    set rowcount 0declare @idstr varchar(8000) 
    set @idstr= '1,2,3'select
        nid
    into 
        #t1
    from
        #t
    where
        nid <= len(@idstr)+2
        and
        substring(','+@idstr+',',nid,1) = ','
        select
        id
    from    
        (select 
             id = substring(','+@idstr+',',nid+1,(select min(nid) from #t1 where nid>a.nid)-nid-1) 
         from 
             #t1 a) b
    where
        id not in(select id from #A) and id is not null
      

  7.   

    pbsql(风云) 正解 
    给分