Home Forums SQL Server 7,2000 T-SQL Parse Full Name Into Last, First and Middle RE: Parse Full Name Into Last, First and Middle

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