Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Parsing out the MiddleName from the FirstName field.

Posted on 2007-04-10
3
Medium Priority
?
284 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 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

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
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

636 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