1

I have text like this:

San Demetrio Corone (CS)
Villanova Tulo (NU)

I need to get the text between parentheses, I did this

SELECT SUBSTRING(a.place, CHARINDEX('(', a.place) + 1, CHARINDEX(')', a.place, CHARINDEX('(', a.place)+ 1)  - CHARINDEX(')', a.place) - 1)
FROM tab1 a

but I'm getting error about lenght parameter, what's wrong in that?

1 Answer 1

3

Your length input to SUBSTRING is off. The length should be the difference in position between the closing and opening parentheses, offset by one less.

SELECT
    place,
    SUBSTRING(place,
              CHARINDEX('(', place) + 1,
              CHARINDEX(')', place) - CHARINDEX('(', place) - 1) AS abbr
FROM tab1;

screen capture from demo link below

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, i Just needed to wait some minutes, I'm doing it now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.