110,534
社区成员
发帖
与我相关
我的任务
分享
select B.name from B where
instr(B.nameid+';',(select A.nameT+';' from A where A.Id="111"))>0
看看行不行,还是4楼的方法,注意一点:你的A的ID字段是什么类型,int还是字符串。谢4楼吧select B.name from B where charindex(B.nameid+';',(select A.nameT+';' from A where A.Id=111))>0
create table A
(
ID int,
nameT varchar(50)
)
create table B
(
nameid varchar(10),
name varchar(20)
)
insert into A
select 111,'aaa;bbb;ccc'
insert into B
select 'aaa','名1' union
select 'bbb','名2' union
select 'ccc','名3'
update A set nameT='aaa;bbb'
select b.name from
(select * from A) as a left join
(select * from B) as b on charindex(b.nameid,a.nameT)>0
where a.id='111'
name
--------------------
名1
名2