zw612003 发表于 2013-12-19 00:05 
求教SQL高级写法。
SQL中没有现成的函数,我自己写了一个
create function stringTimes(@string1 varchar(100),@string2 varchar(100))
returns int
as
begin
declare @len1 int,@len2 int,@index int,@times int
set @len1=len(@string1)
set @len2=len(@string2)
set @index=1
set @times=0
while @index<=@len1-@len2+1
begin
if(substring(@string1,@index,@len2)=@string2)
begin
set @times=@times+1
set @index=@index+1
end
else
set @index=@index+1
continue
end
return @times
end
go