July 6, 2009 at 2:54 pm
Sergiy (7/5/2009)
Jeff Moden (7/2/2009) Andrew already did exactly what I would do...
I would not.
There was a member of Led Zeppelin, John Paul Jones.
Would not be happy seeing his name after such "parsing".
Sergiy is actually the most correct on this. Full name parsing is dangerous at best especially considering that you can have 3 part last names like Van de Graff or the like. The proper way to do this is to head the data provider in the head with a bat and get them to provide the data in the correct format of last name being it's own column.
I've built a splitter for this type of thing including many of the 3 part names, but no lookup list in the world is going to be able to resolve all the names in the world. The data must be entered correctly in some GUI somewhere.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 3, 2016 at 9:23 am
I found this post in trying to split a full name with first, middle and last. I came up with this solution and thought I would share, in case it can help someone else:
,CASE WHEN LTRIM(RIGHT(@fullname,(len(@fullname)-charindex(',',@fullname)))) LIKE '%.%'
THEN REPLACE(LTRIM(RIGHT(@fullname,(len(@fullname)-charindex(',',@fullname)))),REVERSE(left(REVERSE(@fullname), charindex(' ',REVERSE(@fullname))-1)),'')
ELSE LTRIM(RIGHT(@fullname,(len(@fullname)-charindex(',',@fullname)))) END AS First
,ISNULL(CASE WHEN RIGHT(REVERSE(left(REVERSE(@fullname), charindex(' ',REVERSE(@fullname))-1)),1) = '.'
THEN REVERSE(left(REVERSE(@fullname), charindex(' ',REVERSE(@fullname))-1)) END,'') AS Middle
,LTRIM(RTRIM(LEFT(@fullname, CHARINDEX(',', @fullname)-1))) AS Last
February 3, 2016 at 9:40 am
misscrf (2/3/2016)
I found this post in trying to split a full name with first, middle and last. I came up with this solution and thought I would share, in case it can help someone else:
,CASE WHEN LTRIM(RIGHT(@fullname,(len(@fullname)-charindex(',',@fullname)))) LIKE '%.%'
THEN REPLACE(LTRIM(RIGHT(@fullname,(len(@fullname)-charindex(',',@fullname)))),REVERSE(left(REVERSE(@fullname), charindex(' ',REVERSE(@fullname))-1)),'')
ELSE LTRIM(RIGHT(@fullname,(len(@fullname)-charindex(',',@fullname)))) END AS First
,ISNULL(CASE WHEN RIGHT(REVERSE(left(REVERSE(@fullname), charindex(' ',REVERSE(@fullname))-1)),1) = '.'
THEN REVERSE(left(REVERSE(@fullname), charindex(' ',REVERSE(@fullname))-1)) END,'') AS Middle
,LTRIM(RTRIM(LEFT(@fullname, CHARINDEX(',', @fullname)-1))) AS Last
You should warn that it only works with the following format:
LastName, FirstName MiddleInitial.
If the comma is missing, it might generate errors. If the point for the middle initial is missing, it will give incorrect information. So this is highly dependent on correct format of the name which might be useless in many cases.
February 3, 2016 at 9:43 am
Jeff Moden (7/6/2009)
Sergiy (7/5/2009)
Jeff Moden (7/2/2009) Andrew already did exactly what I would do...
I would not.
There was a member of Led Zeppelin, John Paul Jones.
Would not be happy seeing his name after such "parsing".
Sergiy is actually the most correct on this. Full name parsing is dangerous at best especially considering that you can have 3 part last names like Van de Graff or the like. The proper way to do this is to head the data provider in the head with a bat and get them to provide the data in the correct format of last name being it's own column.
I've built a splitter for this type of thing including many of the 3 part names, but no lookup list in the world is going to be able to resolve all the names in the world. The data must be entered correctly in some GUI somewhere.
It works only for a specific style (format) of name. That's the problem with trying to split "free text" columns, especially names.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 16 through 18 (of 18 total)
You must be logged in to reply to this topic. Login to reply