How do I combine the contents of two fields into one in access?

G

Guest

Need to combine two fields into one in a customer database table, for
example; first name field and last name field need to combine into a new
field called first/last name, for the purpose of creating a primary key field
to avoid duplicate records. Any help would be greatly appreciated!
Thomas
 
N

Nikos Yannacopoulos

Thomas,

Assuming the original table is called tblCustomers, and has two fields
called LName and FName, and you have created a new one called
FirstLastName, then you need to run an update query on it like:

UPDATE tblCustomers SET [FirstLastName] = [LName] & "," & [FName]

This is not a robust solution, though, unless you have some kind of
guarantee that you will only ever have one John Smith... which of course
there isn't! That's why people tables always involve some unique primary
key, even though it may not be meaningful. For instance, in the US, the
standard PK used is the social security number which is guarateed to
exist for every person, and be unique. In other countries when nothing
similar exists, one common workaround is to use just an autonumber
field. Give it some thought...

HTH,
Nikos
 
J

Joseph Meehan

Thomas said:
Need to combine two fields into one in a customer database table, for
example; first name field and last name field need to combine into a
new field called first/last name, for the purpose of creating a
primary key field to avoid duplicate records. Any help would be
greatly appreciated!
Thomas

In situations where you can't guarantee the uniqueness of any single field,
you may be able to designate two or more fields as the primary key. The most
common situation where this arises is in the table used to relate two other
tables in a many-to-many relationship. For example, an Order Details table
can relate the Orders and Products tables. Its primary key consists of two
fields: OrderID and ProductID. The Order Details table can list many
products and many orders, but each product can only be listed once per
order, so combining the OrderID and ProductID fields produces an appropriate
primary key.

Each product can be listed only once per order.

Another example would be an inventory database that uses a field part number
of two or more fields (part and subpart).
If you are in doubt about whether you can select an appropriate combination
of fields for a multiple-field primary key, you should probably add an
AutoNumber field and designate it as the primary key instead. For example,
combining FirstName and LastName fields to produce a primary key is not a
good choice, since you may eventually encounter duplication in the
combination of these two fields.

In a multiple-field primary key, field order may be important to you. The
fields in a multiple-field primary key are sorted according to their order
in table Design view. You can change the order of the primary key fields in
the Indexes window.


Note, First and last name may not be a great choice as you may have more
than one Tom Jones or you may have someone enter Tom Jones and next time
enter Thomas Jones.
 
V

Van T. Dinh

1. People names should never be used as PK. There are different people
with the same name!

2. Assume that it were OK to use names as PK, you are much better off to
leave LastName and FirstName as separate Fields and define the PK as a
multi-Field PrimaryKey (in this case 2-Field PrimaryKey). This way, you
still have the flexibility of showing First-Last or Last-First depending on
the requirements.
 
G

Guest

Nikos desribed best how to do this. However, I would like to add that my
company of 1100 employees has 6 sets of people with the same first and last
name, and coincidentally, three of those sets work in the same departments.
Now this company is spread over 6 geographic regions, but even yet, two of
these personnel had the same supervisor. So, again, the combination of first
and last name may not be the best choice.
 
Å

Åí˳¾ü

My name is Peng Shun jun, Why are they english
Nikos Yannacopoulos said:
Thomas,

Assuming the original table is called tblCustomers, and has two fields
called LName and FName, and you have created a new one called
FirstLastName, then you need to run an update query on it like:

UPDATE tblCustomers SET [FirstLastName] = [LName] & "," & [FName]

This is not a robust solution, though, unless you have some kind of
guarantee that you will only ever have one John Smith... which of course
there isn't! That's why people tables always involve some unique primary
key, even though it may not be meaningful. For instance, in the US, the
standard PK used is the social security number which is guarateed to exist
for every person, and be unique. In other countries when nothing similar
exists, one common workaround is to use just an autonumber field. Give it
some thought...

HTH,
Nikos
Need to combine two fields into one in a customer database table, for
example; first name field and last name field need to combine into a new
field called first/last name, for the purpose of creating a primary key
field to avoid duplicate records. Any help would be greatly appreciated!
Thomas
 
N

Nikos Yannacopoulos

Hi Peng Shun Jun,

I am afraid I do not understand your question; why are what english?

Nikos

Åí˳¾ü said:
My name is Peng Shun jun, Why are they english
Nikos Yannacopoulos said:
Thomas,

Assuming the original table is called tblCustomers, and has two fields
called LName and FName, and you have created a new one called
FirstLastName, then you need to run an update query on it like:

UPDATE tblCustomers SET [FirstLastName] = [LName] & "," & [FName]

This is not a robust solution, though, unless you have some kind of
guarantee that you will only ever have one John Smith... which of course
there isn't! That's why people tables always involve some unique primary
key, even though it may not be meaningful. For instance, in the US, the
standard PK used is the social security number which is guarateed to exist
for every person, and be unique. In other countries when nothing similar
exists, one common workaround is to use just an autonumber field. Give it
some thought...

HTH,
Nikos
Need to combine two fields into one in a customer database table, for
example; first name field and last name field need to combine into a new
field called first/last name, for the purpose of creating a primary key
field to avoid duplicate records. Any help would be greatly appreciated!
Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top