?
Solved

Statement to split out first and last name in query

Posted on 2014-01-09
4
Medium Priority
?
506 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
[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
  • 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 2000 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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

752 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