Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Parse Full Name Into Last, First and Middle Expand / Collapse
Author
Message
Posted Wednesday, November 19, 2003 6:04 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 12:46 PM
Points: 64, Visits: 72
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!




Post #18362
Posted Wednesday, November 19, 2003 7:49 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, September 23, 2009 9:40 AM
Points: 940, Visits: 54
Just yesterday...

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

--Jonathan




--Jonathan
Post #87739
Posted Wednesday, November 19, 2003 7:58 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 12:46 PM
Points: 64, Visits: 72
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.




Post #87740
Posted Wednesday, November 19, 2003 8:26 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, September 23, 2009 9:40 AM
Points: 940, 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
Post #87741
Posted Monday, July 15, 2013 12:27 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, July 15, 2013 1:18 PM
Points: 3, 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
Post #1473841
Posted Monday, July 15, 2013 12:49 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:31 PM
Points: 13,207, Visits: 12,688
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 Moden's 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)
Post #1473851
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse