三.求第一个字符串中第二个串的个数

--创建函数
create function [dbo].[m_count]
(
    @str_one nvarchar(200),  --第一个字符串
    @str_two nvarchar(200)   --第二个字符串
)
returns int as
begin
    declare @sqlcount int
    select @sqlcount=(len(@str_one)-len(replace(@str_one,@str_two,'')))/len(@str_two)
return @sqlcount
end
 
--测试示例
select dbo.m_count('sqlserver','e') as [count]
 
--运行结果
/*
count
-----------
2
*/
View Code

 

posted on 2013-12-19 10:15  Dralion  阅读(184)  评论(0)    收藏  举报

导航