Solved

How to trim string in Access

Posted on 2001-09-12
7
303 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies 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…

770 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