select b.id,b.itel,b.sid from b,a where a.title='A' and charindex(','+a.id+',',','+b.sid+',')>0

解决方案 »

  1.   

    1,2,... 有限制吗,没限制最好用函数,有限制,可以一条Sql语句处理
      

  2.   

    declare @t1 table(id int,title varchar(10))
    insert @t1
    select 1,  'A' union all
    select 2,  'B' union all
    select 3,  'C'
    declare @t2 table(id int,title varchar(10),sid varchar(100))
    insert @t2
    select 1,   'test1',   '1,2' union all
    select 2,   'test2',   '2,3' union all
    select 3,   'test3',   '1,3' union all
    select 4,   'test4',   '3'select b.* from @t2 b 
    inner join @t1 a on charindex(',' + rtrim(a.id) + ',',',' + b.sid + ',') > 0 
    where a.title = 'A'
      

  3.   

    看错意思了
    select* from b where charindex(','+'A'+',',','+sid+',')>0
      

  4.   

    select b.*
    from b,a
    where a.title='A'
    and ','+b.sid+',' like '%,'+cast(a.sid as varchar(50))+',%'
      

  5.   

    declare @t1 table(id int,title varchar(10))
    insert @t1
    select 1,  'A' union all
    select 2,  'B' union all
    select 3,  'C'
    declare @t2 table(id int,title varchar(10),sid varchar(100))
    insert @t2
    select 1,   'test1',   '1,2' union all
    select 2,   'test2',   '2,3' union all
    select 3,   'test3',   '1,3' union all
    select 4,   'test4',   '3'select b.* from @t2 b 
    inner join @t1 a on charindex(',' + rtrim(a.id) + ',',',' + b.sid + ',') > 0 
    where a.title = 'A'