SELECT [Copy of NPY Services QuerylName].Names,
Left([Names],InStr(1,[Names],",")-1) AS LastName,
Mid([Names],InStr(1,[Names],",")+1) AS FirstName
FROM [Copy of NPY Services QuerylName];
This is one of the biggest reasons to not put spaces in table, form, report,
and field names. You MUST remember to use square brackets [] if you have
spaces. I recommend underscores _ instead of spaces in all names.
Also this in the table name looks weird: QuerylName . Is that the name of
the table or query?
Speaking of names, "Names" is the name of the field in the table/query,
isn't it? Make sure.
--
Jerry Whittle
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.
Cai said:
Jerry,
I am trying hard but getting syntax errors.
Pls check below for me anything I did wrong.
The database is called Copy of NPY Services.
I typed:
SELECT Copy of NPY Services QuerylName.Names,
Left([Names],InStr(1,[Names],",")-1) AS LastName,
Mid([Names],InStr(1,[Names],",")+1) AS FirstName
FROM Copy of NPY Services QuerylNames;
Thanks
Henry
Cai said:
Thanks Jerry,
Pls show me where to input the following commands?
SELECT tblNames.Names,
Left([Names],InStr(1,[Names],",")-1) AS LastName,
Mid([Names],InStr(1,[Names],",")+1) AS FirstName
FROM tblNames;
Gratefully
Henry
:
Sure. However there could be problems if some, even one, record doesn't have
a comma in it. Also if someone swapped around the first and last names.
Middle initials and middle names also could present problems.
But if the data is clean and formatted as you say, 50K records or more
should work OK if not a little slow.
--
Jerry Whittle
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.
:
Thanks Jerry,
Will this work on the whole "more than 10K" names?
:
If your names are like "John,Smith", something like the following will work
in a query once you plug in the proper table and field names. However if they
have middle names, spaces around the comma, on missing commas, well.......
SELECT tblNames.Names,
Left([Names],InStr(1,[Names],",")-1) AS LastName,
Mid([Names],InStr(1,[Names],",")+1) AS FirstName
FROM tblNames;
--
Jerry Whittle
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.
:
I received a database that contains >10K names in the form of "John,Smith"
with no space. I need to convert this field into two as in "John" and
"Smith". Your help will be greatly appreciated.