Solved

Statement to split out first and last name in query

Posted on 2014-01-09
4
500 Views
Last Modified: 2014-01-09
Hello.  I have a field that has a persons first and last name formatted like this  
LASTNAME, FIRSTNAME

I need to split them out into to fields in my query.

So - how do I get everything BEFORE the comma in one cell.... and everything AFTER the comma in another cell?  also I would like everything after the comma not to have a space between , Firstname.

Thanks
0
Comment
Question by:joylene6
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39769225
You can use the split function after retrieving from the query:

dim arr as variant

arr = Split(YourString, ",")

That being said, a much better (and easier) Database design would be to define separate columns for first name and last name.   That way you can join them easily in any manner you need to.

You should never combine more than one object (such as first and last name) into a single column.

A similar design should also apply to addresses.  you would not want to make one field called address and then store all of street address, city, state, zip all in the one field.  You should make a separate column for each of them.
0
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39769233
You can use the LEFT and MID functions along with the INSTR function to do this.
Use Instr to find the position of the comma and use that value (minus 1) as the second value to LEFT. Use the same technique with MID, but subtract the position value from the length (LEN) of the string.

It would look something like:
LASTNAME: Left([name],InStr([name],",")-1)
FIRSTNAME: Mid([name], Instr(1, [name], ", ") + 2)
0
 
LVL 1

Author Comment

by:joylene6
ID: 39769249
Thanks will give it a try
0
 
LVL 1

Author Comment

by:joylene6
ID: 39769612
Shaun Kline - thanks that worked!

Ken - the database had information in it that I could not change and did not create, but yes I totally agree with you

Thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

831 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