[导入]自己编写一个SQL Server中用的lastindexof函数

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



文章来源:http://www.cnblogs.com/didasoft/archive/2007/12/27/1017196.html
posted @ 2007-12-27 16:52  HappyQQ  阅读(684)  评论(0)    收藏  举报