create table #tb (vNo varchar(15))
insert into #tb
select '2006206110' 
union all
select '2006216700' 
union all
select '2006236570' 
union all
select '2006237470' 
union all
select '2006007030' 
union all
select '2006069140' select * from #tb
当我想查询'2006007030' '2006069140' '20061010888'
只返回'20061010888',因为我的表里面没有'20061010888'

解决方案 »

  1.   


    create table #tb (vNo varchar(15)) 
    insert into #tb 
    select '2006206110'  
    union all 
    select '2006216700'  
    union all 
    select '2006236570'  
    union all 
    select '2006237470'  
    union all 
    select '2006007030'  
    union all 
    select '2006069140'goselect * from
    (
    select '2006007030' tblColumn 
    union all 
    select '2006069140'  
    union all 
    select '20061010888'
    ) as tbl
    where not exists(select * from #tb where vNo = tblColumn)
      

  2.   

    create table #tb (vNo varchar(15)) 
    insert into #tb 
    select '2006206110'  
    union all 
    select '2006216700'  
    union all 
    select '2006236570'  
    union all 
    select '2006237470'  
    union all 
    select '2006007030'  
    union all 
    select '2006069140'  
    select * from (
    select '2006007030' as vno union select '2006069140' union select '20061010888' )a
    where vno   not in (select vno from #tb )
    drop table #tb
      

  3.   

    create table #tb (vNo varchar(15))
    insert into #tb
    select '2006206110' 
    union all
    select '2006216700' 
    union all
    select '2006236570' 
    union all
    select '2006237470' 
    union all
    select '2006007030' 
    union all
    select '2006069140'  
    create procedure test @vNO AS VARCHAR(15) OUTPUT
    AS
    SELECT TOP 1 @vNO FROM #TB WHERE VNO<>@VNOEXEC  TEST '20061010888'
      

  4.   

    create table #tb (vNo varchar(15)) 
    insert into #tb 
    select '2006206110'  
    union all 
    select '2006216700'  
    union all 
    select '2006236570'  
    union all 
    select '2006237470'  
    union all 
    select '2006007030'  
    union all 
    select '2006069140'  Create table #tab (a varchar(20))
    insert into #tab
    select '2006007030'  union 
    select  '2006069140' union
    select '20061010888'select * from #tab where a not in (select vNo from #tb )
      

  5.   


    create table #tb (vNo varchar(15)) 
    insert into #tb 
    select '2006206110'  
    union all 
    select '2006216700'  
    union all 
    select '2006236570'  
    union all 
    select '2006237470'  
    union all 
    select '2006007030'  
    union all 
    select '2006069140'  declare @sql varchar(200)
    set @sql='2006007030,2006069140,20061010888'
    select @sql=replace(','+@sql+',',','+vno+',','') from #tb
    select  replace(@sql,',','')
      

  6.   

    use HC
    create table #tb (vNo varchar(15)) 
    insert into #tb 
    select '2006206110'  
    union all 
    select '2006216700'  
    union all 
    select '2006236570'  
    union all 
    select '2006237470'  
    union all 
    select '2006007030'  
    union all 
    select '2006069140'  declare @sql varchar(200)
    set @sql='2006007030,2006069140,20061010888'
    select @sql=replace(','+@sql+',',','+vno+',','') from #tb
    select  replace(@sql,',','') vNo
    drop table #tb
      

  7.   

    declare @sql varchar(200)
    set @sql='2006007030,2006069140,20061010888'
    select @sql=replace(','+@sql+',',','+vno+',','') from #tb
    select  replace(@sql,',','')顶这个