Search code examples
sqlstringsql-server-2008

What is best way to get last indexof character in SQL 2008


In C#, we have String.LastIndexOf method to get a last index of a particular character location for given string. Is there any similar function to do same in SQL Server? I tried using CHARINDEX but couldn't achieve it.


Solution

  • A little tricky, but you could do something like:

    REVERSE(SUBSTRING(REVERSE([field]),0,CHARINDEX('[char]',REVERSE([field]))))