Solved

How to trim string in Access

Posted on 2001-09-12
7
289 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
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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now