Make query that remove characters, and copy removed characters to a new field


Have a table in mysql that contains of a field (navn) like:
Arne Hansen
Per Iversen
Ole Berg

What i want is to copy Hansen,Iversen and Berg to a new field(etternavn)
And remove Hansen,Iversen and Berg from navn field..

How can i do this...

I can olso do this from visual studio 2008, if this is not possible with a query.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Assuming all values are just two words:

update table_name set
etternavn = substring_index(substring(navn,1+(length(navn)-length(substring_index(navn,' ',-1)))),' ',1),
navn = substring(navn,1,(length(navn)-length(substring_index(navn,' ',-1))));

(just so happens i did something very similar not so long ago and I still have the code =) )

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
team2005Author Commented:

WOW, thanks so very match...

Works very good...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.