-1

Can someone tell me how to find the character index from the end?

Example:

John(Jk)

I want to find the ( from the end.

Result:

4
jarlh
  • 35,821
  • 8
  • 33
  • 49
Aravindhan R
  • 251
  • 4
  • 24

3 Answers3

1

One way to rephrase your question is that you want to find the first occurrence of ( from the reversed string.

SELECT
    LEN(col) - CHARINDEX('(', REVERSE(col)) + 1
FROM yourTable;

Demo

In the above demo, the char index of the final ( in the string John(Jk) correctly is determined to be 5.

Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263
0

Use charindex() with reverse() function to find the index from the end

select charindex('(', reverse(data)) from table
Yogesh Sharma
  • 47,987
  • 5
  • 21
  • 48
-1

You can use CHARINDEX.

Syntax:

CHARINDEX ( expressionToFind , expressionToSearch [ , start_location ] )   

Best Regarads!