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'
看错意思了 select* from b where charindex(','+'A'+',',','+sid+',')>0
select b.* from b,a where a.title='A' and ','+b.sid+',' like '%,'+cast(a.sid as varchar(50))+',%'
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'
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'
select* from b where charindex(','+'A'+',',','+sid+',')>0
from b,a
where a.title='A'
and ','+b.sid+',' like '%,'+cast(a.sid as varchar(50))+',%'
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'