select * from b where charindex(','+convert(varchar,id)+',',@b_list+',')>0

解决方案 »

  1.   

    select a.id,(select [你要查的字段]  from tbb where id in( a.b_list ) from tba a
      

  2.   

    select * 
    from b
    inner join a
    on len(a.b_list) - len(replace(','+b.id+',',','+a.b_list+',','')) > 0
      

  3.   

    create function reS(int @a)
    return varchar(1000)
    as
    declare @s varchar(1000)
    select @s=b_list from a where [id]=@a
    set @s=@s+','
    return @sselect b.* from b,a where charindex(','+convert(varchar,id)+',',dbo.reS(a.id)>0根据vivianfdlpw() 想的,没测试,楼主看看
      

  4.   

    create table ta(id int, b_list varchar(40))
    create table tb(id int, value varchar(10))
    go
    insert ta select 1, ',1,2,3,4,5,6' union all select 2, ',5,6,7,8,9'
    insert tb select 1, 'a' union all select 2, 'b' union all select 3, 'c'
    insert tb select 4, 'd' union all select 5, 'e' union all select 6, 'f'
    insert tb select 7, 'g' union all select 8, 'h' union all select 9, 'i'
    go
    --主要部分
    create function fun(@b_list varchar(40))
    returns varchar(100)
    as
    begin
       declare @str varchar(100)
       set @str=@b_list+','
       select @str=replace(@str, ','+convert(varchar(10), id)+',', ','+value+',')  
       from tb
       set @str=left(@str, len(@str)-1)
       return @str
    end
    go
    select id, b_list=dbo.fun(b_list) from ta
    --清除
    drop function fun
    drop table ta
    drop table tb
      

  5.   

    上面写错了少了一括号
    select a.id,(select [你要查的字段]  from tbb where id in( a.b_list )) from tba a
      

  6.   

    --例子:
    --查出ta表中id为2的b_list对应的tb表数据:
    select value from tb,ta where charindex(convert(varchar(5),tb.id),b_list)<>0 and ta.id=2