Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I remove parenthesis and everything that comes after it? 1

Status
Not open for further replies.

accesshelp1

Technical User
Feb 8, 2023
1
0
0
US
I have a query that shows IDs with a parenthesis and another ID. I only want the first ID and to remove the ID within the parenthesis.
For example an ID looks like this: 12345 (54321). I would like to have the data return 12345 and completely drop the parenthesis and everything that comes after it and I can't figure out how to do this.

The biggest challenge here is not all IDs are the same length so I can't just use a TRIM.

I tried Replace ( Replace(Replace([ID],"(",""),")","")) but that added a space in between the two IDs, meaning ONLY the parentheses was removed and the ID ended up looking like this 12345 54321.

Does anyone know how to remove everything that would come past the parenthesis?

Thanks
 
Something like this should work:

Code:
Trim(Left([ID],Instr([ID]&"(","(")-1))

If there is no "(", it would add one to avoid an error.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
You can also do:
[tt]
Update YourTableName
Set ID = [blue]Trim(Split(ID, "(")(0))[/blue]
Where InStr(ID, "(") > 0[/tt]

Welcome to Tek-Tips [wavey3]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
>I tried Replace ( Replace(Replace([ID],"(",""),")","")) but that added a space in between the two IDs
Well, that did not add a Space, you already did have a Space in there, right?

You could, instead of detecting a "(", you could go after the Space between ID's, ignoring the "(" :)
[tt]
Update YourTableName
Set ID = Trim(Split(ID, " ")(0))
Where InStr(ID, " ") > 0[/tt]

or
[tt]
Update YourTableName
Set ID = Left(ID, InStr(ID, " ") -1)
Where InStr(ID, " ") > 0[/tt]


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top