Link to home
Start Free TrialLog in
Avatar of gogetsome
gogetsomeFlag for United States of America

asked on

Update author names from last first to first last

Hello, I have a mixed column of names similar to this:

Lawrence, Michael
Getty, Keith
Getty, Kristyn
NULL
NULL
Mainetti Stefano  
Various          
Nelson Bibles    

I need to perform an update statement that will correct the author name if it is last,first.

So if the column contains a comma, put the word after the comma first then a space then the word before the comma and finely remove the comma.


How can this be accomplished?
Avatar of Aneesh
Aneesh
Flag of Canada image

update yourTable
SET Name = RIGHT(Name, len(Name) - charindex(',', Name) )+' ' +LEFT(Name, len(Name) - charindex(',', Name)-1 )
where name like '%,%'
Avatar of ggzfab
ggzfab

Try a column like:

case when charindex(', ','Lawrence, Michael')>0 then  SUBSTRING ('Lawrzzence, Michael',charindex(', ','Lawrzzence, Michael')+1,999) + ' ' + left('Lawrence, Michael',charindex(', ','Lawrence, Michael')-1)  end

Open in new window



Just replace 'Lawrence, Michael' with your fieldname.
Avatar of gogetsome

ASKER

Thank you aneeshattingal!

That almost did it but left the comma at the end of the name

I suppose we could run that statement, but how to get rid of the comma at the end of the name if exists?
Seems like you got a space after the comma

Update your table
set name = replace (name, ',','')
where name like '%,%'
Aneeshattingal,

another issue for me is that the column also contains company names like

Antiquities Research Films, Inc.

became

 Inc. Anti

any way around this as well?
How do you distinct between a company name and a person's name  ?
I inherited a mess.

The only pattern I can see is single word coma single word and not update to rows that don't fall into that pattern.

Is that possible?
You can update the where condition.

select Name,updatedName = RIGHT(Name, len(Name) - charindex(',', Name) )+' ' +LEFT(Name, len(Name) - charindex(',', Name)-1 )
from your table
where name like '%,%'
and name not like '%.%'
On the surface that does look better but look what it is doing

Morecraft, Joe       Joe Mor


Can't have it truncating parts of an authors name.
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you so much for helping Aneeshattingal! That will work and seems to be my only option.