September 7, 2015 at 2:59 pm
IS there a script I can change firstname lastname to lastname, firstname:
for example John Smith, to Smith, John
September 7, 2015 at 3:14 pm
Not really. This assumes that nobody has a name like "Billy Joe" or a last name with spaces in it either... which is a gross simplification.
SELECT LEFT(FullName,CHARINDEX(' ',FullName)-1) AS x
, RIGHT(FullName,LEN(FullName)-CHARINDEX(' ',FullName)) AS y
FROM
(SELECT 'John Smith' AS FullName) x;
September 7, 2015 at 3:15 pm
oops... double post...
September 8, 2015 at 6:29 am
Reformatting full names is a pain and something you can't really automate in the real world without some problems. Take this example:
SELECT LEFT(FullName,CHARINDEX(' ',FullName)-1) AS x
,RIGHT(FullName,LEN(FullName)-CHARINDEX(' ',FullName)) AS y
FROM
(SELECT 'Sarah Michelle Gellar' AS FullName) x;
You really should have different columns for first and last names. You could even add middle name and second last name.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply