Split a field based on first occuring space from left and . . .


I have a field where I want to extract the all characters that are left of the first occurring space.  But I also want to extract the characters if there is no space in the field.

So for example.  I have created a field that I call, "FirstPart"  In it I want information taken from a field called "First":

Field: First
Record 1: Jim K.
Record 2: Susan

When I run an update query to the FirstPart field; Left([First],InStr([First]," ")-1)

I get:

Field: FirstPart
Record 1: Jim K.
Record 2: (blank)

I experimented with used Mid and Instrrev, but not getting any results.  That would be due to my inexperience in using those functions.

Any thoughts?


Who is Participating?
Jim Dettman (Microsoft MVP/ EE MVE)Connect With a Mentor PresidentCommented:
You want:

IIF(Instr([First]," ")>0,Left([First],InStr([First]," ")-1),[First])

Jeffrey CoachmanMIS LiasonCommented:
Questions like these are typically dependent on being able to handle each and every data entry inconsistency.

What is there is no name? (blank, Null)
What if there is no space.
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
try this
Update tableName
Set [FirstPart]=Left([First] &" ",InStr([First] & " "," ")-1)
ListriteAuthor Commented:
Thanks Jim and Capricorn,

Tried both solutions and they worked great.  So with that in mind, couldn't really choose which to select as the "Best Solution"

boag2000: Thanks for your reply.  The only requirement I had was to retrieve information in records that had information in the First field.  So any nulls, blanks, did not matter in this case.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.