Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turning 1 Field Into 3

Status
Not open for further replies.

manfran

Technical User
May 26, 2003
4
0
0
US
Hi All,
I have a table that has one field for contact names. I need to create a new table that splits that field into 3 (FirstName, MiddleIN, LastName). Some contacts have first name only, some have first name middle initial and last name and most have first and last name. How do I handle this?
 
Hi,

First remove multiple spaces from contacts field, make sure there is only one space between words.
Remove spaces at the begining of the field, if any.
Count the words in the field.
Create an array of word count elements.
Assign each word as an element of the array.
Then parse the field with something like this:
Code:
do case
case word_count = 1 first name only
     FirstName  = array(1)
     MiddleIn   = ' '
     LastName   = ' '
case word_count = 2 first and last name
     FirstName  = array(1)
     MiddleIn   = ' '
     LastName   = array(2)
case word_count = 3 first name, middle initial, last name
     FirstName  = array(1)
     MiddleIn   = array(2)
     LastName   = array(3)
endcase

And don't forget to backup. Hope this helps.
 
Check out this thread:
thread184-579353

Much of it is specific to Foxpro, but you'll find useful code and links as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top