I need to extract the values inside the last parentheses of each row. Column Name is what I have and column ID is what I need.
Notice that row 2 has two set of parentheses and that one row has no parentheses.

I tried using this script:
SUBSTRING(name,CHARINDEX('(',name)+1 ,CHARINDEX(')',name)-CHARINDEX('(',name)-1)
The script returns error message Invalid length parameter passed to the LEFT or SUBSTRING function. because of the the third row has no parentheses.
For your sample data, this should do what you want:
select replace(right(name, charindex('(', reverse(name) + '(') - 1), ')', '')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With