Link to home
Start Free TrialLog in
Avatar of sam2929
sam2929

asked on

Remove ()

Hi,
I have data like below

Rtyu(aaaa)
Na
Kk(dghk)

I want () to be remove so final output should be
Rtyu
Na
Kk
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jim Horn
Copy-paste the below double REPLACE T-SQL into your SSMS, execute it to verify it meets your requirements, then modify to fit your needs:
Declare @str varchar(100) = 'Rtyu(aaaa)
Na
Kk(dghk)'

SELECT REPLACE(REPLACE(@str, '(', ''), ')', '')

Open in new window

@Jim Horn

op wants to remove all content inside (..) as well as brackets, not just remove brackets :)
Aah.  Missed that part..
if you want to update your data

update myTable
   set data = left(data, CHARINDEX('(',data)-1) 
 where CHARINDEX('(',data)>0

Open in new window

SELECT LEFT(data, CHARINDEX('(', data + '(') - 1)
  select  left(filedname,CHARINDEX('(',fieldname + '(')-1) as myvalue  from tablename

Open in new window

Avatar of cativiela valerie
cativiela valerie

hi,
ure not saying is in all cases ur datas are ending with ')'. if its not always the case, the SELECT LEFT(data, CHARINDEX('(', data + '(') - 1)  will not work
otherwise its quite clever way to do it.
ure not saying is in all cases ur datas are ending with ')'. if its not always the case, the SELECT LEFT(data, CHARINDEX('(', data + '(') - 1)  will not work
otherwise its quite clever way to do it.
I have a condition in both select and update version

ID: 42127489
ID: 42127501

when CHARINDEX('(',data)>0 then ... else ...

WHERE CHARINDEX('(',data)>0
im sorry i dont get how its solving it. i mean, if u have f.e. TTT(IUIUU)VVVV or (HHHH)UUUUU and u want to obtain TTTVVVV and UUUUUU, have only what is left of the "(" wil not be ok?
ofc, if ure sure to have in any case only like GGG(UUU) or FFFF, then no worries :)

thats what i was asking, maybe i didnt put it properly :)