自己编写一个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

你可能感兴趣的:(sql,sql,server)