Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove text within parenthesis in SQL

I'm trying to remove parenthesis and text within it. Eg: Column1 has data and cleaned data should look like column2

Column1       Column2
HF(abcd)      HF
BP(234)       BP
ATRS (2354)   ATRS
AB(PS) SD(12) AB SD

I'm trying to use the below regex just to view the cleaned data, But I'm doing it wrong

s/([^)]*)//

select Column1 from table where Column1 like '%s/\([^)]*\)//%'

What is the best possible solution for this

like image 685
shockwave Avatar asked Dec 24 '22 13:12

shockwave


1 Answers

THIS ANSWERED THE ORIGINAL VERSION OF THE QUESTION.

What regular expression? You just want everything before the (:

select left(column1, charindex('(', column1) - 1)

If you might not have the opening paren, you can do:

select left(column1, charindex('(', column1 + '(') - 1)
like image 89
Gordon Linoff Avatar answered Dec 27 '22 05:12

Gordon Linoff