Parse Full Name Into Last, First and Middle

  • 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!

  • Just yesterday...

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

    --Jonathan



    --Jonathan

  • 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.

  • 
    
    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

  • 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

  • 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 http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply