sqlsever 判断某个字段出现重复的字母或字符

-------下面使用标量值函数判断  出现重复的个数


create function fn_str_times
(
@str varchar(1000),--原子符串
@indexstr varchar(20)--查找的字符
)
returns int
as
begin
declare @findlen int
declare @times int
set @findlen=LEN(@indexstr)
set @times=0
while(charindex(@indexstr,@str))>0
BEGIN
set @str=SUBSTRING(@str,CHARINDEX(@indexstr,@str)+@findlen,len(@str))
set @times=@times+1
end
 
return @times
end

posted @ 2018-02-02 18:32  王子先生  阅读(435)  评论(0编辑  收藏  举报