表A 字段b nvarchar (256)字段B里会存放一组编号 s0001,s0002,s0003,s0004(这从s0001,到s0004都是一条记录这个字段内容,)表D
字段c nvarchar(12)
c里会存放一个编码 s0002现在要把表D中c字段存在于B字段的记录都找出来,咋整?不知道说清楚没有select * from  D where c …………不会写了

解决方案 »

  1.   

    select * from  D where charindex(','+c+',', ','+b+',')>0
      

  2.   

    select d.* from d inner join a on a.b = d.c
      

  3.   

    --测试数据 看过f哥都是以这种格式写的 学习写了一个
    if object_id('a') is not null drop table a
    go
    create table a(b varchar(200))
    insert into a 
    select 's0001,s0002,s0003,s0004' union all
    select 's0001,s0005,s0002' union all
    select 's0001,s0005'if object_id('d') is not null drop table d
    go
    create table d(c varchar(50))
    insert into d
    select 's0002'--查询
    select m.b from a as m , d as t where charindex(t.c,m.b)>0
      

  4.   

    select * from  D where exists (select 1 from a where charindex(','+c+',', ','+b+',')>0)