>I have a tab delimited file from a spreadsheet that
>has a field "Name" (includes first and last name).
>
>I am importing the file into a table that has
>"firstName" and "lastName" as seperate fields.
>
>Is there a way to split the field from the text file
>"Name" into two different fields in the database,
>"firstName" and "lastName"?
>
>I would assume the last word in "Name" is the last
>name for "lastName" in mysql table.
>
>Thanks,
>
>=====
>--
>Anthony Ettinger
>[EMAIL PROTECTED]
>415-504-8048
>http://chovy.com/resume.doc

That's ugly.  You can't do it with LOAD DATA, but if your first-name
or last-name fields are long enough to hold the entire name, you can
load the values into one of those columns and then split the name
afterward.  Assuming there is exactly one space in a name, and assuming
the names are loaded into last_name, you can do this:

UPDATE tbl_name SET first_name = SUBSTRING_INDEX(last_name,' ',1);
UPDATE tbl_name SET last_name = SUBSTRING_INDEX(last_name,' ',-1);

Here's an example of how this works:

mysql> SET @last_name = "Paul Revere";
mysql> SET @first_name = SUBSTRING_INDEX(@last_name,' ',1);
mysql> SET @last_name = SUBSTRING_INDEX(@last_name,' ',-1);
mysql> SELECT @first_name, @last_name;
+-------------+------------+
| @first_name | @last_name |
+-------------+------------+
| Paul        | Revere     |
+-------------+------------+

-- 
Paul DuBois, [EMAIL PROTECTED]

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to