27,580
社区成员
发帖
与我相关
我的任务
分享
create table webite
(id int,
[content] varchar(2000))
insert webite
select 1 ,'一次测试' union
select 2,'几环' union
select 3,'一次测试,二次试,三次测试'
select a.id,substring([content], number, charindex(',', [content] + ',', number) - number) as col
into ttt
from webite a,master..spt_values b
where b.type='p'
and substring(',' + [content], number,1) = ','
create function getstr(@id int)
returns varchar(max)
as
begin
declare @s varchar(500)
select @s=isnull(@s+',','')+col from ttt
where id=@id and charindex('测试',col)>0
return @s
end
select distinct id,dbo.getstr(id) from ttt
where dbo.getstr(id) is not null
--------------------
1 一次测试
3 一次测试,三次测试