我用的是Access,现在有一个ID,比如说ID=1,现在我要在一个字段(Class_IDPath)里去找有没有匹配的。
Class_IDPath里的格式大概是这样的
Class_IDPath
0,10,11,111,112
0,1, 22,333,444
0,11,22,333,1请问我要怎样才能将里面Class_IDPath包含1的所有数据找出来?以前用Instr或者Like都不行.

解决方案 »

  1.   

    where ','+id+',' like '%'+Class_IDPath+'%'
      

  2.   

    access不知道怎么搞 SQL2005你看下if not object_id('Tab') is null
        drop table Tab
    Go
    Create table Tab(id int identity(1,1),Class_IDPath nvarchar(20))
    Insert Tab
    select '0,10,11,111,112' union all
    select '0,1,22,333,444' union all
    select '0,11,22,333,1'
    Go
    with thb as
    (
    select 
        a.id,b.Class_IDPath
    from 
        (select id,Class_IDPath=convert(xml,'<root><v>'+replace(Class_IDPath,',','</v><v>')+'</v></root>') from Tab)a
    outer apply
        (select Class_IDPath=C.v.value('.','nvarchar(100)') from a.Class_IDPath.nodes('/root/v')C(v))b
    )
    select * from thb where Class_IDPath=1
    /*
    id         
    -----------
    2           
    3           
    */