• I didn't compare head to head, but I would think something like this might perform better with longer strings:

    -- NOTE: this uses the len function, so this function ignores whitespace at end also

    CREATE FUNCTION dbo.LastIndexOf(

    @char as char

    , @string as varchar(max)

    )

    RETURNS integer

    AS

    BEGIN

    SET @string = rtrim(@string)

    if len(@string) = 0

    return 0

    DECLARE @revString as varchar(max)

    DECLARE @lastIndex as integer

    SET @revString = reverse(@string)

    SET @lastIndex = charIndex(@char, @revString) -- find the last char in the reverse string

    IF @lastIndex = 0

    return 0

    SET @lastIndex = len(@string) - @lastIndex + 1 -- flip it so counting from the front

    RETURN @lastIndex

    END