Solved

Statement to split out first and last name in query

Posted on 2014-01-09
4
491 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
Comment Utility
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 25

Accepted Solution

by:
Shaun Kline earned 500 total points
Comment Utility
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
Comment Utility
Thanks will give it a try
0
 
LVL 1

Author Comment

by:joylene6
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

772 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

15 Experts available now in Live!

Get 1:1 Help Now