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)
 splitin one field into two

Author  Topic 

reklan
Starting Member

4 Posts

Posted - 2004-04-16 : 05:16:43
I have a problem that I cannot seem to solve, so I am asking for help.

I have a table that contains the following fields

surname, fornames, initial, titles etc.

Now these fields not only contain single names etc but also contain joint names. i.e.

surname | fornames | initial | titles
Pearson Dave D Mr
Pearson & Smith Dave & Elaine D & E Mr & Mrs


I would like to be able to create a view that would split joint names into new fields ie. Surname2, forenames2 etc.

All the joint names are separated by the '&' so names before it stay in the original field and everything after it is put into the new field.

Is this possible and can it be done.

Many thanks


Dave

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-04-16 : 05:34:38
break this into smaller parts...

1. a joint-name field should by the example above have 4 &'s in it
2. find the 1st &...and the word after it (id'd by a space either side of it) is the surname
3. find the 2nd &...and the word after it (id'd by a space either side of it) is the firstname
4. find the 3rd &...and the word/letter after it (id'd by a space either side of it) is the initial
5. find the 4th &...and the word after it (id'd by a space either side of it) is the title
6. any records with < 4 &....need to have different coding applied.


search here using the keywords 'splitting names address'....and you'll come across code snippets which will get you moving along....
Go to Top of Page
   

- Advertisement -