Removing Brackets and the content within SQL query

I have a column in my database called Horse_Name. This currently includes the country if outside of UK in brackets (ire),(fra) ect.

Is it possible to run a query to remove the brackets and the content very much like in excel whereby you can replace all (*) within the given column?

An example would be as follows

Current                        Outcome

Horse_Name                    Horse_Name

Rocket(FRA)                  Rocket   
Apple Jade(IRE)              Apple Jade
Zac                          Zac

Open in new window

I would like to go through the whole column named Horse_Name to remove the brackets and data.

I have tried the following code but it only finds the values and does not replace them

SELECT REPLACE(Horse_Name, SUBSTRING(Horse_Name, LOCATE('(', Horse_Name), LENGTH(Horse_Name) - LOCATE(')', REVERSE(Horse_Name)) - LOCATE('(', Horse_Name) + 2), '') AS Horse_Name
FROM TFResults;
Kind Regards,

Open in new window


J
runnerjp2005Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
You would need an UPDATE query for that, something like this perhaps.

UPDATE TFResults
SET Horse_Name = SUBSTRING(Horse_Name, LOCATE('(', Horse_Name), LENGTH(Horse_Name) - LOCATE(')', REVERSE(Horse_Name)) - LOCATE('(', Horse_Name) + 2), '')
0
runnerjp2005Author Commented:
Thanks - that does make sense but i am getting a syntax error Capture.PNG
0
NorieAnalyst Assistant Commented:
Try this.

UPDATE TFResults
SET Horse_Name = TRIM(SUBSTRING(CONCAT(Horse_Name,'('), 1, LOCATE('(', CONCAT(Horse_Name,'('))-1))
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

runnerjp2005Author Commented:
The script looks to work to an extent but now I am running into another issue

Capture.PNG
To prevent duplicate entry's I use a key which is taken from horse name and the date (A horse would not complete twice on the same day). Why would updating the field cause a duplicate entry error?
0
runnerjp2005Author Commented:
Thanks for your help - I have successfully ran the script!
0
NorieAnalyst Assistant Commented:
What I suggested removes everything after the first '(' rather than everything within the brackets and the brackets themselves.

I can adjust the expression to only remove the latter if that's what you really need.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.