CREATE FUNCTION dbo.lastindexof (@stringValue as nvarchar(1000), @stringSearch as nvarchar(1000), @startPosition as int = 0)
returns int
AS
BEGIN
DECLARE @lastindex int
SET @lastindex= @startPosition
DECLARE @tempindex int
while (1=1)
begin
SET @tempindex = charindex(@stringSearch, @stringValue, @lastindex + 1)
if (@tempindex = 0)
break
SET @lastindex = @tempindex
end
RETURN(@lastindex)
END
本文介绍了一个SQL自定义函数,该函数用于在指定的字符串中查找另一个字符串最后一次出现的位置,并返回其索引。此函数通过使用T-SQL语言编写,能够在Microsoft SQL Server环境中运行。
676

被折叠的 条评论
为什么被折叠?



