A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How to split data in one field into two fields?



 
 
Thread Tools Display Modes
  #1  
Old June 21st, 2004, 08:27 PM
Amit
external usenet poster
 
Posts: n/a
Default How to split data in one field into two fields?

Windows XP, Access 2000
========================
Hi,

I have a table with a field for firstName and another for
lastName. Unfortunately, the suffixes for the person (eg.
Jr., II, RN, RD, PhD etc.) were entered along with the
last name. So, the lastName has data values like "Roberts,
RN" or "Clinton Jr.". I'd like to create another field and
then split the data to keep just the last name in the
lastName field, and the rest in the Suffix field.

Desired:
---------
lastName | Suffix
====================
"Roberts" | "RN"
"Clinton" | "Jr."

I've looked at the string functions in the help section,
but didn't find any function that would help me accomplish
this. I guess I'm looking for something similar to
the "Data--Convert Text to Columns" in MS Excel.

I could export the data from Access to Excel, split it,
and then import it back. But would prefer to do this
without importing/exporting data.

Thanks for any help or pointers regarding this.

-Amit
  #2  
Old June 21st, 2004, 09:42 PM
Jay Vinton
external usenet poster
 
Posts: n/a
Default How to split data in one field into two fields?

Unfortunately, the suffixes for the person (eg.
Jr., II, RN, RD, PhD etc.) were entered along with the
last name.


Hi Amit,

There is no magic way to resolve this. My approach (after tracking down the original designer and asking him to spend his next vacation fixing it) would be to get methodical.

1. Add new columns to the table for anything missing such as Title (Mr., Sra...), MiddleInitial, Suffix (Jr., III ...)

2. Make a list of all the likely bits you are looking for (" Jr.", " Jr", " Junior", etc). Don't forget likely typos like "Juniro" and hope it's not part of a real name...

3. For each probable suspect, get a result set
"Select LastName From Customers Where LastName Like '* Jr.';"

4. [Optional] Review the results to see if you got anything that looks like it doesn't fit. If you find anything, refine your search criteria.

5. Write some code that goes through the result and, using Mid() and Instr(), parse the name and save each part to separate variables. Then write them back to the correct columns.

It's unlikely that it will be perfect when you are finished.

Hope that helps

Jay


  #3  
Old June 21st, 2004, 09:50 PM
Amit
external usenet poster
 
Posts: n/a
Default How to split data in one field into two fields?


-----Original Message-----
Unfortunately, the suffixes for the person (eg.
Jr., II, RN, RD, PhD etc.) were entered along with the
last name.


Hi Amit,

There is no magic way to resolve this. My approach (after

tracking down the original designer and asking him to
spend his next vacation fixing it) would be to get
methodical.

1. Add new columns to the table for anything missing such

as Title (Mr., Sra...), MiddleInitial, Suffix (Jr.,
III ...)

2. Make a list of all the likely bits you are looking for

(" Jr.", " Jr", " Junior", etc). Don't forget likely typos
like "Juniro" and hope it's not part of a real name...

3. For each probable suspect, get a result set
"Select LastName From Customers Where LastName Like '*

Jr.';"

4. [Optional] Review the results to see if you got

anything that looks like it doesn't fit. If you find
anything, refine your search criteria.

5. Write some code that goes through the result and,

using Mid() and Instr(), parse the name and save each part
to separate variables. Then write them back to the correct
columns.

It's unlikely that it will be perfect when you are

finished.

Hope that helps

Jay


Hi Jay,

Thanks for your response. It *is* definitely helpful. Just
need to be more careful when designing databases in future.

-Amit
  #4  
Old June 25th, 2004, 03:33 AM
Mark King
external usenet poster
 
Posts: n/a
Default How to split data in one field into two fields?

-----Original Message-----
I have a table with a field for firstName and another

for lastName. I'd like to create another field and
then split the data to keep just the last name in the
lastName field, and the rest in the Suffix field.
-Amit


Take a look at "Splitter for Microsoft Access"
Splits names in Access tables, including suffixes!
http://www.infoplan.com.au/splitter

- Mark K.


  #5  
Old June 25th, 2004, 04:44 PM
Kate Was Here
external usenet poster
 
Posts: n/a
Default How to split data in one field into two fields?

This might be unhelpful but I had to do the reverse of this once (ie combine two columns into one) and there may be an opposite method:

1. make a copy of the database to work from
2. then transfer the relevant columns (firstname and lastname in my particular case) into Excel and then use the concatenate formula
3. This gave me the data in one column (double check by skimming the column)
4. Paste the column back into the table.

There is probably the reverse of concatenation in excel although I have never used it.

Good luck!

"Mark King" wrote:

-----Original Message-----
I have a table with a field for firstName and another

for lastName. I'd like to create another field and
then split the data to keep just the last name in the
lastName field, and the rest in the Suffix field.
-Amit


Take a look at "Splitter for Microsoft Access"
Splits names in Access tables, including suffixes!
http://www.infoplan.com.au/splitter

- Mark K.



  #6  
Old August 24th, 2004, 10:07 PM
BC-w2k3s
external usenet poster
 
Posts: n/a
Default

It looked interesting. So, I thought I'd try out solving this. In Excel, you
can use the SEARCH/REPLACE combination. But, this was possibly a little more
clean.

SELECT tblVendors.VendorName,
IIf(InStr([vendorname],",")0,Left([vendorname],InStr([vendorname],",")-1))
AS [first],
IIf(InStr([vendorname],",")0,Trim(Mid([vendorname],InStr([vendorname],",")+1))) AS [Last]
FROM tblVendors;

This is a simple select query, with tblVendors being the table in question,
and VendorName being the field to split up.
I would create two extra fields and change this query to an update query
when you feel comfortable with it. You will also want to go through the code
and note any inconsitencies. This also assumes that you are merely looking
for a comma.

Hope it helps...if you get this.

BC

"Amit" wrote:

Windows XP, Access 2000
========================
Hi,

I have a table with a field for firstName and another for
lastName. Unfortunately, the suffixes for the person (eg.
Jr., II, RN, RD, PhD etc.) were entered along with the
last name. So, the lastName has data values like "Roberts,
RN" or "Clinton Jr.". I'd like to create another field and
then split the data to keep just the last name in the
lastName field, and the rest in the Suffix field.

Desired:
---------
lastName | Suffix
====================
"Roberts" | "RN"
"Clinton" | "Jr."

I've looked at the string functions in the help section,
but didn't find any function that would help me accomplish
this. I guess I'm looking for something similar to
the "Data--Convert Text to Columns" in MS Excel.

I could export the data from Access to Excel, split it,
and then import it back. But would prefer to do this
without importing/exporting data.

Thanks for any help or pointers regarding this.

-Amit

  #7  
Old August 24th, 2004, 11:06 PM
Paul Johnson
external usenet poster
 
Posts: n/a
Default

Looks like you need to search for spaces (not commas) in the lastname field,
since one of the two examples you gave did not have a comma. You can use
this expression to parse out the suffixes in a query:

Trim(Mid(LastName, InStr(LastName, " ") + 1))

You can test it in a SELECT query:

SELECT Trim(Mid([LastName],InStr([LastName]," ")+1)) AS SuffixTest
FROM tblVendors;

and if the results look right to you, then change the query to an update
query and run it.

UPDATE tblVendors SET Suffix = Trim(Mid([LastName],InStr([LastName],"
")+1));

You will need to have already added the Suffix field to your table to run
the update query.

HTH
Paul

"BC-w2k3s" wrote in message
...
It looked interesting. So, I thought I'd try out solving this. In Excel,

you
can use the SEARCH/REPLACE combination. But, this was possibly a little

more
clean.

SELECT tblVendors.VendorName,

IIf(InStr([vendorname],",")0,Left([vendorname],InStr([vendorname],",")-1))
AS [first],

IIf(InStr([vendorname],",")0,Trim(Mid([vendorname],InStr([vendorname],",")
+1))) AS [Last]
FROM tblVendors;

This is a simple select query, with tblVendors being the table in

question,
and VendorName being the field to split up.
I would create two extra fields and change this query to an update query
when you feel comfortable with it. You will also want to go through the

code
and note any inconsitencies. This also assumes that you are merely looking
for a comma.

Hope it helps...if you get this.

BC

"Amit" wrote:

Windows XP, Access 2000
========================
Hi,

I have a table with a field for firstName and another for
lastName. Unfortunately, the suffixes for the person (eg.
Jr., II, RN, RD, PhD etc.) were entered along with the
last name. So, the lastName has data values like "Roberts,
RN" or "Clinton Jr.". I'd like to create another field and
then split the data to keep just the last name in the
lastName field, and the rest in the Suffix field.

Desired:
---------
lastName | Suffix
====================
"Roberts" | "RN"
"Clinton" | "Jr."

I've looked at the string functions in the help section,
but didn't find any function that would help me accomplish
this. I guess I'm looking for something similar to
the "Data--Convert Text to Columns" in MS Excel.

I could export the data from Access to Excel, split it,
and then import it back. But would prefer to do this
without importing/exporting data.

Thanks for any help or pointers regarding this.

-Amit



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:48 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.