Home Forums SQL Server 2005 T-SQL (SS2K5) Find last occurence of a character within a string RE: Find last occurence of a character within a string

  • Ramesh (4/8/2009)


    Or this way too...

    DECLARE @SomeFile VARCHAR(255)

    SET @SomeFile = 'C:\WINDOWS\system32\FileName.xls'

    SELECT RIGHT( @SomeFile, CHARINDEX( '\', REVERSE( @SomeFile ) + '\' ) - 1 )

    Perfect solution..with simple trick using REVERSE...