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)
 Extracting middle name from first name field

Author  Topic 

bendertez
Yak Posting Veteran

94 Posts

Posted - 2007-09-10 : 05:24:52
Hello

I know this is a relatively simple task , but how do you split one single firstname field in to two fields i.e first and middle for all records in sql server?

I want the new first name field to obviuosly be the first part of the name. However, if there is not a middle name then I want the new first name field to have the name in and the new middle name field to be NULL.

i.e
firstnamefield
Anne Marie
Sarah Jane
Jenny

in to

NewFirstnamefield
Anne
Sarah
Jenny

NewMiddlenamefield
Marie
Jayne
NULL (I don't want the word NULL, i just want an empty field)

The following code nearly gets me there, but if there is no middle name it returns the first name in the new middle name field and not the new first name field.

SUBSTRING(table.forenames, 0, CHARINDEX(' ',table.forenames)) AS 'First Name',
SUBSTRING(table.forenames,CHARINDEX(' ', table.forenames),100) AS 'Middle Name',

Any ideas?

Thank you

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-10 : 06:14:02
DUPLICATE POST
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=89102



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -