Solved

Parsing out the MiddleName from the FirstName field.

Posted on 2007-04-10
3
274 Views
Last Modified: 2012-05-05
I have just added a MiddleName column to my table.  I need to parse out the MiddleName or Initial (Anything after the first Space in the FirstName) from the FirstName Column and Update both the FirstName and Middle Name column.
0
Comment
Question by:DigitalDan3
  • 2
3 Comments
 
LVL 14

Expert Comment

by:mherchl
Comment Utility
update yourtable
set MiddleName = ltrim(rtrim(substring(ltrim(FirstName), charindex(' ', ltrim(FirstName)), 1+len(FirstName)- charindex(' ', ltrim(FirstName))))),
FirstName = substring(ltrim(FirstName), 0, charindex(' ', ltrim(FirstName)))
0
 

Author Comment

by:DigitalDan3
Comment Utility
This statement worked for FirstNames that contained a MiddleName however, FirstName that did not have a Middlename or Initial were moved to middlename
0
 
LVL 14

Accepted Solution

by:
mherchl earned 500 total points
Comment Utility
sorry for that, this should work:

update yourtable
set MiddleName = ltrim(rtrim(substring(ltrim(FirstName), charindex(' ', ltrim(FirstName)), 1+len(FirstName)- charindex(' ', ltrim(FirstName))))),
FirstName = substring(ltrim(FirstName), 0, charindex(' ', ltrim(FirstName)))
where charindex(' ', ltrim(FirstName)) <> 0
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now