SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Parse Full Name Into Last, First and Middle


Parse Full Name Into Last, First and Middle

Author
Message
Joe Salvatore
Joe Salvatore
SSC-Addicted
SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)

Group: General Forum Members
Points: 458 Visits: 77
I am trying to develop a custom function that when given a Full Name formatted as Lastname Suffix., Firstname Middlename can be parsed into individual parts. I envision this accepting the Full Name and an indicator for the individual part desired (e.g Lastname, Middlename, or Firstname).
What would be the best and most efficent manner to construct this function?
Example formatted Fullname Johnson Sr., John Richard.
THANKS Community for any prompt assistance!



Jonathan
Jonathan
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2785 Visits: 54
Just yesterday...

http://www.sqlservercentral.com/forum/link.asp?TOPIC_ID=18145

--Jonathan



--Jonathan
Joe Salvatore
Joe Salvatore
SSC-Addicted
SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)

Group: General Forum Members
Points: 458 Visits: 77
Thanks for the guideance however I have reviewed those solutions and the topic referenced assumed the name is delimited with spaces and as such does not provide enough of a guideline for me to develop a "best practice" approach for my situation of having the Full Name formatted as lastname<space>suffix.,<space>firstname<space>middlename.



Jonathan
Jonathan
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2785 Visits: 54

declare @n varchar(40)
set @n = 'Johnson Sr., John Richard'
SELECT LEFT(@n,CHARINDEX(',',@n)-1) LastName,
PARSENAME(REPLACE(STUFF(@n,1,CHARINDEX(',',@n)+1,''),' ','.'),2) FirstName,
PARSENAME(REPLACE(STUFF(@n,1,CHARINDEX(',',@n)+1,''),' ','.'),1) MiddleName


--Jonathan



--Jonathan
ajlefort
ajlefort
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 3
Hi,
I need to parse last name,first name space middle name.
Example A - DOE,JOHN
Example B - DOE,JOHN A

I am able to parse the last name.
left(dbo.AbstractData.Name, charindex(',', dbo.AbstractData.Name)-1) as last name

I can parse the first and middle names together.
ltrim(right( dbo.AbstractData.Name,(len(dbo.AbstractData.Name)-charindex(',',dbo.AbstractData.Name))))
as firstmiddlename

I can parse the middle name.
SUBSTRING(dbo.AbstractData.Name,CHARINDEX(' ',dbo.AbstractData.Name + ' ')+1,LEN(dbo.AbstractData.Name))

I am having trouble parsing the first name. The first name is everything after the comma and before the first blank after the comma (or the end of the string, in which case there is no middle name).
Can anyone help me parse the first name only?

Thanks
Sean Lange
Sean Lange
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62129 Visits: 17954
ajlefort (7/15/2013)
Hi,
I need to parse last name,first name space middle name.
Example A - DOE,JOHN
Example B - DOE,JOHN A

I am able to parse the last name.
left(dbo.AbstractData.Name, charindex(',', dbo.AbstractData.Name)-1) as last name

I can parse the first and middle names together.
ltrim(right( dbo.AbstractData.Name,(len(dbo.AbstractData.Name)-charindex(',',dbo.AbstractData.Name))))
as firstmiddlename

I can parse the middle name.
SUBSTRING(dbo.AbstractData.Name,CHARINDEX(' ',dbo.AbstractData.Name + ' ')+1,LEN(dbo.AbstractData.Name))

I am having trouble parsing the first name. The first name is everything after the comma and before the first blank after the comma (or the end of the string, in which case there is no middle name).
Can anyone help me parse the first name only?

Thanks


please stick to your own thread for this.

http://www.sqlservercentral.com/Forums/Topic1473843-8-1.aspx

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search