Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 problem

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-23 : 16:43:56
Tassos writes "Hi guys, i've got a broblem here..
I have one field (char 50) named "eponimo" and a second field (char 30) named "onoma".
In the "eponimo" field i have stored both Surname and Name values separated with a space and the "onoma" field its empty. I want to seperate the "eponimo" into the two fields one for the Name ("onoma")and the other for the Surname ("eponimo").

thanks

regards Tassos"

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2005-08-23 : 17:22:57
Hi Tassos,
I'm assuming you've stored it "firstname surname". If not, just reverse the destinations of the updates
UPDATE 
dbo.MyTable
SET
eponimo = RIGHT(RTRIM(eponimo), CHARINDEX(' ', REVERSE(RTRIM(eponimo)))-1),
onoma = LEFT(eponimo, CHARINDEX(' ', eponimo)-1)

Run this in a transaction followed by a select and a rollback to make sure you are happy with the results before committing. The RTRIM is required because of the datatypes. I'd advise changing these from CHAR to VARCHAR as the length of the entries will vary.

Mark
Go to Top of Page
   

- Advertisement -