Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Parsing Name data

Author  Topic 

0341
Starting Member

21 Posts

Posted - 2008-04-02 : 14:23:04
I am trying to take a string that contains a first name, middle initial and last name and break it down into 3 separate columns. Not sure how to do this. Please help

-Phil

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-02 : 14:46:22
[code]SELECT PARSENAME(REPLACE(NameField,' ','.'),3) AS firstname,
PARSENAME(REPLACE(NameField,' ','.'),2) AS middlename,
PARSENAME(REPLACE(NameField,' ','.'),1) AS lastname
FROM YourTable[/code]
Go to Top of Page

0341
Starting Member

21 Posts

Posted - 2008-04-02 : 15:08:17
That works unless the person doesn't have a middle name then it puts the person's first name in the middle name field.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-04-02 : 16:29:29
What are your rules for parsing the string? Do you have sample data and expected output?
Go to Top of Page
   

- Advertisement -