create FUNCTION fn_GetSimilar ( @StrA As Varchar(255), --传入的待比较的字符 @StrB As Varchar(255) --期望字符 ) RETURNS int AS BEGIN DECLARE @Result int declare @lenA int declare @lenB int declare @lenSameA int declare @lenSameB int set @lenA=len(@StrA) set @lenB=len(@StrB) --计算A中字符在B中存在的数量 select @lenSameA=count(*) from dbo.fn_splitstr(@strA) where @StrB like '%'+splitValue+'%' --计算B中字符在A中存在的数量 select @lenSameB=count(*) from dbo.fn_splitstr(@StrB) where @StrA like '%'+splitValue+'%' set @Result =(@lenSameA+@lenSameB)*100 /(@lenA+@lenB) RETURN @Result END select dbo.fn_getsimilar('asdf','fdsa')