Split out FirstName, LastName, MiddleName

  • One column name as [MemberName] in which stored data like

    LastName, FirstName M (with initial middle name)

    or

    LastName, FirstName (without initial middle name)

    How to create a function to split out two columns [First name] and [Last name]?

  • Something like this?

    WITH CTE([MemberName])AS(

    SELECT 'Cazares, Luis' UNION ALL

    SELECT 'Cazares, Luis A')

    SELECT LEFT( MemberName, CHARINDEX(',', MemberName) - 1) LastName,

    SUBSTRING( MemberName, CHARINDEX(',', MemberName) + 1, LEN( MemberName)) FirstName

    FROM CTE

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thank you for help.

    We are getting there but if MemberName is 'Cazares, Luis A' I want to display as 'Cazares, Luis' as well.

    How modify code?

Viewing 3 posts - 1 through 2 (of 2 total)

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