• ColdCoffee (7/30/2012)


    I use it mostly to parse out the file names from a long file path. Example:

    DECLARE @FilePath VARCHAR(100)

    SET @FilePath = 'C:\Users\abcd\AppData\Local\Temp\Temp.txt'

    SELECT REVERSE(LEFT ( REVERSE(@FilePath) , CHARINDEX('\',REVERSE(@FilePath))))

    Instead of finding the last backslash throu string splitters, i used combination of functions along with REVERSE to do the task..

    Generalisation - sometimes you'll find that a certain character in a string is repeated several times, and you want to extract the chunk of the string between the last occurrence of this character and the end of the string.

    Without REVERSE(), this would be quite involved. ColdCoffee's solution shows how easy it is with REVERSE().

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.