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.
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 lastnameFROM YourTable[/code] |
 |
|
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. |
 |
|
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? |
 |
|
|
|
|