('''','''',@str,@start)
while (@location <>0 and @index > @next )
begin
select @start = @location +1
select @location = charindex('''','''',@str,@start)
select @next =@next +1
end
if @location =0 select @location =len(@str)+1 --如果是因为没有逗号退出,则认为逗号在字符串后
select @str_return = substring(@str,@start,@location -@start) --@start肯定是逗号之后的位置或者就是初始值1
if (@index <> @next ) select @str_return = '''''''' --如果二者不相等,则是因为逗号太少,或者@index小于@next的初始值1。
return @str_return
end
3、 测试
SELECT [dbo].[getstrarrlength](''''1,2,3,4,a,b,c,d'''')
SELECT [dbo].[getstrofindex](''''上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >> |