Need to remove round brackets () along with the content in between in string

I have discover a string where some of the values have the round brackets with content.   I need to remove the brackets along with the text between them.  Not all records have the offending round brackets.  See the example below.


      FROM dbo.Locations

Texas (231)
Alabama (32)
Georgia (1)
Who is Participating?

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

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.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
select left(location, case when charindex('(', location) > 0 then charindex('(', location)-2 else len(location) end) from 
select 'Texas (231)' as location
select 'Alabama (32)'
select 'Florida'
) x

Open in new window

Of course you should replace the test data by your table Locations.
Najam UddinCommented:
SELECT LEFT(Location, CHARINDEX('(', Location) - 1) FROM dbo.Locations

Open in new window

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Slightly optimized, and with your table:
select case when charindex('(', location) > 0 then left(location, charindex('(', location)-2) else location end
from dbo.locations

Open in new window

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
wdbatesAuthor Commented:
I never know what the content will be so your example will not work.

Najam Uddin

Error  Message

Msg 537, Level 16, State 2, Line 1
Invalid length parameter passed to the LEFT or SUBSTRING function.

Your example works.  You get the points.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
FYI, the first comment is a common way to test SQLs - by providing the test data with it. You should be able to transform that into your correct query yourself.
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
Microsoft SQL Server 2008

From novice to tech pro — start learning today.