字符串A为
(01)(12)(1201)(1300)(15)表T中有个字段ID,Bianhao
数据
ID   Bianhao
1     00
2     01
3     12
4     1300
……怎样验证A中包含的编号在T中是否存在
若不存在则从串A中删除该编号
如结果:
(01)(12)(1300)求SQL语句

解决方案 »

  1.   

    declare @str varchar(200)
    set @str='(01)(12)(1201)(1300)(15)'
    select * into #temp from table where charindex(Bianhao,@str)>0select @str=stuff((select '('+Bianhao+')' from #temp for xml path('')),1,1,'')) from #temp
      

  2.   

    create table aa
    (
    ID int,
    Bianhao varchar(20)
    )
    insert into aa
    select 1,'00'
    union select 2,'01'
    union select 3,'12'
    union select 4,'1300'declare @str varchar(200)
    set @str='(01)(12)(1201)(1300)(15)'
    select * into #temp from aa where charindex('('+Bianhao+')',@str)>0select @str='('+stuff((select '('+Bianhao+')' from #temp for xml path('')),1,1,'') from #tempprint @str--------------
    (4 行受影响)(3 行受影响)
    (01)(12)(1300)
      

  3.   

    create table aa
    (
        ID int,
        Bianhao varchar(20)
    )
    insert into aa
    select 1,'00'
    union select 2,'01'
    union select 3,'12'
    union select 4,'1300'declare @temp table (bianhao varchar(32))
    declare @str2 varchar(max)
    set @str2=''
    declare @str1 varchar(200)--set @str1='(021)(212)(12201)(13040)(153)(003)'
    set @str1='(021)(212)(12201)(13040)(153)(003)(00)'
    insert into @temp 
    select bianhao from aa where charindex('('+Bianhao+')',@str1)>0select @str2=@str2+ '(' +t.bianhao+ ')' from @temp  t inner join aa  b 
    on t.bianhao=b.bianhao
    print @str2
      

  4.   

    declare @str varchar(200)
    set @str='(01)(12)(1201)(1300)(15)'
    select * into #temp from T where charindex('('+Bianhao+')',@str)>0select @str='('+stuff((select '('+Bianhao+')' from #temp for xml path('')),1,1,'') from #tempselect @str