Forum Moderators: open

Message Too Old, No Replies

splitting 1 text field into 2 columns in a DB

how to?

         

webboy1

9:06 am on Sep 24, 2002 (gmt 0)

10+ Year Member



I am looking to split information from one text feild so that it enters into 2 fields in my SQL Server DB.

eg

User types in Micky Mouse as there full name.

The DB result is:

firstname: Mickey
Surname: Mouse

Can anyone help?

P.s. im using ASP and SQL Server

Regards
Webboy

Iguana

9:55 am on Sep 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would use server-side VBSCript to spit up the string before I build up the SQL statement and create/update the record.

The InstrRev function will find the last space in the full name and then you can then use Left() and mid() to get the 2 parts of the name - taking care in case there isn't a space in the name

webboy1

10:11 am on Sep 24, 2002 (gmt 0)

10+ Year Member



Sounds great, but i have little idea what you are talking about. I am fairly new to SQL. I have been coping ok with it, but im getting stuck with this.

is there anyway you could show me an example?

I really have no idea how to set this up.

Thanks for the response

txbakers

12:54 pm on Sep 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi. this isn't a SQL issue, rather a VBSCRIPT or JSCRIPT issue.

Esssentially it works likes this:
(in javascript)
var fullname ="";
fullname = Request.Post("namefield");
var namesplit = String(fullname).split(" ");
var fname = namesplit[0];
var lname = namesplit[1];

This finds the blank space in the string, splits the string into an array and assigns the first part to fname, and the last part to lname.

Of course, should someone enter Fife,Barney you are in trouble.
Same with David Ogden Stiers - three names. The family name will be discarded and he will show up in your DB as David Ogden.

If you need to track two separate names, I would make them two separate input boxes in the form.