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
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
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;
In the above demo, the char index of the final (
in the string John(Jk)
correctly is determined to be 5.
Use charindex()
with reverse()
function to find the index from the end
select charindex('(', reverse(data)) from table
You can use CHARINDEX.
Syntax:
CHARINDEX ( expressionToFind , expressionToSearch [ , start_location ] )
Best Regarads!