Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Separating names in one field

Status
Not open for further replies.

Morelos

MIS
Apr 12, 2000
33
0
0
MX
I am using Delphi 5 with an Access DB and I have this problem...: I have a table with fields 'Name', 'LastName' and would like to convert the 'LastName' field into 2 separate fields 'MiddleName' and 'LastName'. E.g.:

BEFORE
Name=John
LastName=Fitzgerald Kennedy

AFTER
Name=John
MiddleName=Fitzgerald
LastName=Kennedy

I appreciate greatly any help on this matter...







 
Hi,

First create the 'Middlename' field in your table.

then You should write a short code. You should have a table (bde) or adotable component...just call it "dataset".

var
tempstr : string;
...
dataset.open;
...
dataset.first;
while not dataset.eof do
begin
// make sure we have not any space at the beginning or end
tempstr := trim(dataset.fieldbyname('Lastname').AsString);

// if we have a space somewhere in the middle, we split
// the field
if pos(' ', tempstr) > 0 then
begin
dataset.edit;
dataset.fieldbyname('Middlename').AsString :=
leftstr(tempstr, pos(' ', tempstr));
dataset.fieldbyname('Lastname').AsString :=
midstr(tempstr, pos(' ', tempstr) + 1, length(tempstr));
dataset.post;
end;
dataset.next;
end;

so thats it. It's just a code draft, I hope You can use it...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top