Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Statement to split out first and last name in query

Posted on 2014-01-09
4
Medium Priority
?
507 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 27

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
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…

636 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