Search code examples
sqlsql-serverfindpatindex

Sql find the last non-numeric character in a string


How to find last non-numeric character in a string such as "10jnklgm51". In order to find 'm' in the example what is the best simple way?


Solution

  • The last non-numeric character is the first non-numeric character in the reverse string. So, something like this:

    select substring(reverse(str),
                     patindex('%[^0-9]%', reverse(str)),
                     1)