34,576
社区成员
发帖
与我相关
我的任务
分享
if object_id('[tb]') is not null drop table [tb]
go
create table tb (id int, car_id int, tag_name varchar(20))
insert into tb
select '0','0','好看'union all
select '1','0','炫酷'union all
select '2','0','吊炸天'
go
if object_id('[car]') is not null drop table [car]
create table car(id int ,name varchar(20),type varchar(20))
insert into car
select '0','长安CS75','SUV'
go
declare @s varchar(20)
set @s='好看、炫酷'
select car.name,tb.tag_name from tb left join car on tb.id=car.id
where tag_name in
(
select distinct substring(@s,number ,charindex('、',@s+'、',number)-number) from master.dbo.spt_values
where number>=1 and number<=len(@s) and substring('、'+@s,number,1)='、')