Sql统计一个字符串在另一个字符串出现的次数的函数-fnQueryCharCountFromString

时间:2014-01-16 23:29:53   收藏:0   阅读:526
bubuko.com,布布扣
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[fnQueryCharCountFromString](@str varchar(8000),@sub varchar(50))
returns int
as
begin
    declare @pos int,@n int

    select @n=0, @pos=charindex(@sub,@str)

    while(@pos<>0)
    begin
        select @str=right(@str,len(@str)-@pos),@pos=charindex(@sub,@str),@n=@n+1
    end

    return(@n)
end
bubuko.com,布布扣

原文:http://www.cnblogs.com/elves/p/3522011.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!