select 
    o.* 
from 
    t_outbook o,
    t_book b 
where 
    charindex(','+rtrim(b.id)+',',','+rtrim(o.bookid)+',')>0

解决方案 »

  1.   

    select 
        o.* 
    from 
        t_outbook o,
        t_book b 
    where 
        (','+rtrim(o.bookid)+',') like '%,'+rtrim(b.id)+',%'
      

  2.   

    select 
        o.* 
    from 
        t_outbook o,
        t_book b 
    where 
        charindex(','+rtrim(b.id)+',',','+rtrim(o.bookid)+',')>0
        and
        b.bookname='xml'
      

  3.   

    select distinct t1.*
    from t_outbook  t1 left join t_book  t2  on
    t1.bookid = cast(t2.id as varchar) or
    t1.bookid like cast(t2.id as varchar) + ',%' or
    t1.bookid like '%,' + cast(t2.id as varchar)
    where t2.bookname = 'xml'
      

  4.   

    select * from t_outbook 
    where 
    charindex((select cast(id as varchar(10)) from t_book where bookname='xml'),bookid)>0
      

  5.   

    呵呵 问题解决了
    望  子陌老大能详细讲解一下这句话,小弟不是很明白 charindex(','+rtrim(b.id)+',',','+rtrim(o.bookid)+',')>0