insert into w(word)
select('去')
union all
select('第三方')
union all
select(',')
union all
select('士大夫')
union all
select('girls')
union all
select('<:')
select* from w
declare @t nvarchar(1000)
set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地<.'
我想从这句话中找出w表在的关键字并显示出来,包括显示几次。
结果如下:
去 2
第三方 1
, 1
大学看看该如何实现。。
...全文
160071打赏收藏
sql字符查询问题?????急急急!!!!!!
create table w ( word nvarchar(100) ) insert into w(word) select('去') union all select('第三方') union all select(',') union all select('士大夫') union all select('girls') union all select('<:') select* from w declare @t nvarchar(1000) set @t='我们今天要去的地方要和第
--没有 上面的人写得简单 贴出来供参考下。
--写的比较多 比较繁琐--
CREATE function KeyNums
(@key nvarchar(50), @t nvarchar(1000) )
returns int
as
begin
declare @times int
select @times=0
while(1=1)
begin
if exists (select 1 where @t like '%'+@key+'%')
begin
select @times=@times+1
select @t=substring(@t,1,(charindex(@key,@t)-1))
+substring(@t,(charindex(@key,@t)+1),(len(@t)-len(@key)))
end
else
begin
break
end
end
return @times
end
---测试-----
declare @t nvarchar(1000)
select @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地 <:'
select word
,dbo.KeyNums(word,@t)as Nums
from w
insert into w(word)
select('go')
union all
select('third')
union all
select(',')
union all
select('ShiDaFu')
union all
select('girls')
union all
select('<:')