• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

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.

1 Solution
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 =) )
team2005Author Commented:

WOW, thanks so very match...

Works very good...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now