Solved

How to trim string in Access

Posted on 2001-09-12
7
319 Views
Last Modified: 2008-03-03
Hello all,

I have a colum in Access looks like this

Name                                                  Id
Angervil, Moliere (PS, APS)                           1
Arocha, Fernando (PS, Contractor, EDF)                2
...

I need to trim the Name colum that only have the last 3 letters.  In this case, are APS and EDF.  Sometimes there are two ","s and sometimes just one.

How can I do this?

Thanks for your help.
0
Comment
Question by:lisaqin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6477707
You mean you want to get rid of them?

update tbl
set name = left(name,len(name - 6) & ")"
where right(name,6) in (", APD)",", EDF)")
0
 

Author Comment

by:lisaqin
ID: 6477733
Thanks, but this colum contains data has veriable lenght and position.

0
 

Author Comment

by:lisaqin
ID: 6477797
Ok, I guess my question is: How do I find out the position of a charater in a given string?  ie. abcdefgh, the position of d is 4.  Is there a function that I can do that?

Thanks
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 32

Expert Comment

by:bhess1
ID: 6478155
To find the position of a character in a string in Access, use the InStr function, e.g.:

Select InStr("abcdefgh", "d") As DPos

Returns 4

Now, going to your first case, the Right function should work to your advantage:

Select Mid([Name], InStr([Name], ")") - 4,3) As LastEntry
FROM MyTable
0
 
LVL 32

Accepted Solution

by:
bhess1 earned 50 total points
ID: 6478156
Oops - that should be:

Select Mid([Name], InStr([Name], ")") - 3,3) As LastEntry
FROM MyTable
0
 
LVL 10

Expert Comment

by:StephenCairns
ID: 6478466
Hi If you just want to get the last 3 letters within the brackets then you could try either of these.

Mid((Right(RTrim([name]), 4)), 1, 3)

Mid(RTrim([name]), Len(RTrim([name])) - 3, 3)

if there are following spaces the RTrim will remove them
good luck
0
 

Author Comment

by:lisaqin
ID: 6479327
Thank you so much!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question