34,593
社区成员
发帖
与我相关
我的任务
分享
DECLARE @A table (a_id int)
insert into @A values(1)
insert into @A values(2)
insert into @A values(13)
insert into @A values(24)
insert into @A values(35)
insert into @A values(46)
insert into @A values(78)
insert into @A values(100)
select * from @A
--1,2,3,4,5,6,7,8
DECLARE @B table (b_id int,a_id varchar(100))
insert into @B (b_id,a_id) values(1,'1,13,35,46,7,78')
select * from @b
select * from @A where charindex(ltrim(a_id)+',',(select a_id from @b where b_id = 1)) <> 0
select a.*
from a,b
where charindex(','+ltrim(a.a_id)+',',','+b.a_id+',')>0
and b.b_id=1
select t.*
from a t ,b s
where charindex(','+ltrim(t.a_id)+',',','+s.a_id +',')>0
select a.*
from a,b
where charindex(','+ltrim(aid)+',',','+b.a_id+',')>0
and b.b_id=1
select * from a where ','+ltrim(a_id)+',' in (select ','+a_id+',' from b where b_id=1)
select * from a where ltrim(a_id) in (select a_id from b where b_id=1)
if object_id('ta') is not null drop table ta
create table ta(a_id int)
insert into ta values(1)
insert into ta values(2)
insert into ta values(3)
insert into ta values(24)
insert into ta values(35)
insert into ta values(46)
insert into ta values(7)
insert into ta values(100)
--select * from a
if object_id('tb') is not null drop table tb
create table tb (b_id int,a_id varchar(100))
insert into tb (b_id,a_id) values(1,'1,2,3,6,7,8')
declare @sql varchar(1000)
select @sql=a_id from tb where b_id=1
exec('select * from ta where a_id in ('+@sql+')')
动态执行