Skip to content
Advertisement

Is there a LastIndexOf in SQL Server?

I am trying to parse out a value from a string that involves getting the last index of a string. Currently, I am doing a horrible hack that involves reversing a string:

To me this code is nearly unreadable. I just upgraded to SQL Server 2016 and I hoping there is a better way. Is there?

Advertisement

Answer

If you want everything after the last _, then use:

If you want everything before, then use left():

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement