Solved

Parsing out the MiddleName from the FirstName field.

Posted on 2007-04-10
3
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Expert Comment

by:mherchl
ID: 18883289
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
ID: 18883518
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
ID: 18883644
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

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

726 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