Solved

Parsing out the MiddleName from the FirstName field.

Posted on 2007-04-10
3
280 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

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