By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,476 Members | 889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,476 IT Pros & Developers. It's quick & easy.

Splitting one field into two separate fields

P: 1
Hello,

I have a table with one field 'NAME', consisting of the firstname and surname of a person.

I want to split the content of the 'NAME' field into 2 new fields 'FIRSTNAME' and 'SURNAME'. How do I do this with an update query?
Dec 7 '06 #1
Share this Question
Share on Google+
3 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
Hello,

I have a table with one field 'NAME', consisting of the firstname and surname of a person.

I want to split the content of the 'NAME' field into 2 new fields 'FIRSTNAME' and 'SURNAME'. How do I do this with an update query?
Assuming there are no middle names, initials or double barreled names.

You can use the following:

Expand|Select|Wrap|Line Numbers
  1. UPDATE TableName SET FIRSTNAME=Left([NAME], InStr([NAME]," ")-1) And SURNAME=Right([NAME], InStr([NAME]," ")+1);
  2.  
Mary
Dec 7 '06 #2

NeoPa
Expert Mod 15k+
P: 31,602
Assuming there are no middle names, initials or double barreled names.

You can use the following:

Expand|Select|Wrap|Line Numbers
  1. UPDATE TableName SET FIRSTNAME=Left([NAME], InStr([NAME]," ")-1) And SURNAME=Right([NAME], InStr([NAME]," ")+1);
Mary
That would give strange results Mary ;) - Try this :
Expand|Select|Wrap|Line Numbers
  1. UPDATE TableName
  2. SET FIRSTNAME=Left([NAME], InStr([NAME]," ")-1),
  3. SURNAME=Mid([NAME], InStr([NAME]," ")+1);
Dec 7 '06 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Sorry ferdib.

Ade why can't I get that stupid 'AND' out of my head. That's not the first time I've done that.

Mary
Dec 7 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.