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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strip first and last name from field 1

Status
Not open for further replies.

dvannoy

MIS
Joined
May 4, 2001
Messages
2,765
Location
US
I have a field called EmployeeName.

e.g. Smith, John

I need to take the last name from all the records and put those into a field called LastName. I also need to do the same with the FirstName.

Any help would be appreciated.

Thanks

 
The easiest way would be to use SQL SERVERS PARSENAME function,

Example:
SELECT
PARSENAME(REPLACE(fullname, ', ','.'),2) AS Surname,
PARSENAME(REPLACE(fullname, ', ','.'),1) AS Forename
FROM names

This would return:
Surname Forename
--------------- --------------
Smith John


(where fullname = "Smith, John")

This of course assumes 2 names only, surname, forename
 



It is rarely the case, except in a classroom setting, that FullName fields contain TWO and ONLY TWO words.

It is more likely that you will have compound first and/or last names, initials, sufixes, COMMAS incorrectly placed.

Under these real-world conditions, a pre-analysis must take place to categorize and group various patterns. It is an iterative process, that results in several different conversion scenarios.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top