Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Selecting Part of a field

Posted on 2008-06-23
6
Medium Priority
?
205 Views
Last Modified: 2010-03-20
I swear I will get this down eventually!

I need to select only part of a User Name field.  Some of the User names have a middle initial at the very end of the string that I need to remove.

I need to convert:

smith, john a to
smith, john

Thanks!
0
Comment
Question by:mattturley
[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
6 Comments
 
LVL 75
ID: 21848411
Try this:

Mid("smith, john a",1,InStrRev("smith, john a"," ")))

returns smith, john

mx

0
 
LVL 75
ID: 21848421
Generic:

Mid(FullName,1,InStrRev(FullName"," "))

mx
0
 
LVL 75
ID: 21848440
Opps .... extra ""

Mid([FullName],1,InStrRev([FullName]," "))


Query:

SELECT Mid([FullName],1,InStrRev([FullName]," ")) AS Expr1
FROM Table1;

mx
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:mattturley
ID: 21848496
Not every record has a middle initial - when this is the case, the above gets rid of the first name.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 21848539

SELECT IIf(InStr([NameField]," ")<>InStrRev([NameField]," "),Left([NameField],InStrRev([NameField]," ")-1),[NameField]) AS Expr1
FROM Table1;
0
 
LVL 44

Expert Comment

by:GRayL
ID: 21850721
As you can get what you want via a query, I recommend you leave your data intact.  Run this query:

SELECT IIF(instr(mytest," ") = instrrev(mytest," "), mytest, Left(mytest,instr(instr(mytest,", ")+2,mytest," "))) AS JustName FROM myTable;
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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 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