How can you create a field that is concatenated?

  • Thread starter Thread starter Carolb
  • Start date Start date
C

Carolb

Example: I'd like to take the date of birth date which is format like
11/14/1971 and the first three character of the firstname field example:
Carol
I'd like my output to look like car111471 (and I'd like to set that as a
primary key)
How and where do I do this? Query, macro? Any help would be appreciated.

Thank you.
Carol
 
Carolb said:
Example: I'd like to take the date of birth date which is format like
11/14/1971 and the first three character of the firstname field
example: Carol
I'd like my output to look like car111471 (and I'd like to set that
as a primary key)
How and where do I do this? Query, macro? Any help would be
appreciated.

Thank you.
Carol

You don't (if you want to do things properly).

No field in a table should consist of data in other fields.
 
The reason I'm wanting to do this is to create a unique Id. I will have to
tried each individual to different people. What would you recommend then?

The database i'm creating is like a membership. People get paid based on
who they have join. There are two pay structures. There a tier1 and a
tier2. I thought if I created a unique Id I could tie them to the
individuals by putting there Unqiue id in the tier1 field or tier2.
 
Carolb said:
The reason I'm wanting to do this is to create a unique Id. I will
have to tried each individual to different people. What would you
recommend then?

Make a composite PK consisting of both of the fields you already have. No need
to artificially create a new field containing redundant data. Or put a unique
index on those fields to eliminate duplicates and add a surrogate PK using a
number field. This could be an AutoNumber or a Number field that you assign
values to.
 
I thought about using the auto numbering because someone recommend me to say
away from that. I thought that would be an easy thing. I haven't done an
access database in 5 years. It's really showing. I need a book but the
weathers really bad here today! So, I'm stuck at home trying to find crap
online for help! Thank you for responding. I appreciate your advice and time!

Carol
 
You can't count on birthdates and names to give you RELIABLE unique values.
Some people have the same birthdate; they might well have the first three
letters of the name in common too. Or you might not HAVE a birthdate, or a
person might give you a false one and then "come clean" later - now you need
to change your primary key!!

By all means use an autonumber in this case. You can display the date and name
as data, but they do NOT constitute a reliable, stable primary key.

For some online resources see

Jeff Conrad's resources page:
http://www.accessmvp.com/JConrad/accessjunkie/resources.html

The Access Web resources page:
http://www.mvps.org/access/resources/index.html

A free tutorial written by Crystal (MS Access MVP):
http://allenbrowne.com/casu-22.html

MVP Allen Browne's tutorials:
http://allenbrowne.com/links.html#Tutorials
I thought about using the auto numbering because someone recommend me to say
away from that. I thought that would be an easy thing. I haven't done an
access database in 5 years. It's really showing. I need a book but the
weathers really bad here today! So, I'm stuck at home trying to find crap
online for help! Thank you for responding. I appreciate your advice and time!

Carol

John W. Vinson [MVP]
 
You can't count on birthdates and names to give you RELIABLE unique values.
Some people have the same birthdate; they might well have the first three
letters of the name in common too. Or you might not HAVE a birthdate, or a
person might give you a false one and then "come clean" later - now you need
to change your primary key!!

By all means use an autonumber in this case. You can display the date and name
as data, but they do NOT constitute a reliable, stable primary key.

If all of the entity's available attributes produces duplicates then
you have duplicates. Adding an Autonumber simply provides a way of
uniquely identifying the duplicates, it doesn't eliminate them.

Sometimes we need to create an artificial key and expose it to end
users. Most 'Autonumber advocates' I've asked agree that Autonumber
values should not be exposed to end users. I do not think any flavour
of Autonumber is suitable for exposing to end users: incremental
raises objections from auditors when sequences inevitably exhibit
gaps, random generates variable-width and negative values and lack
check digits etc, GUIDs are just too wide to be practical for end
users.

Jamie.

--
 
Jamie said:
Sometimes we need to create an artificial key and expose it to end
users. Most 'Autonumber advocates' I've asked agree that Autonumber
values should not be exposed to end users. I do not think any flavour
of Autonumber is suitable for exposing to end users: incremental
raises objections from auditors when sequences inevitably exhibit
gaps,

Not all databases are subject to auditors nor do all auditors object to gap
sequences.
random generates variable-width and negative values and lack
check digits etc,

I sometimes use random, but display the number in hex. No negative signs
and relatively consistent lengths.
GUIDs are just too wide to be practical for end
users.

Agreed.
 
Not all databases are subject to auditors nor do all auditors object to gap
sequences.

Good point. Substitute "some interested parties", which encompasses
database designers (you must have seen the post where people are
bothered about non-sequential values and we don't seem able to quite
ease their minds...?)
I sometimes use random, but display the number in hex. No negative signs
and relatively consistent lengths.

Are you saying you think this makes the Autonumbers suitable to expose
to end users?

Jamie.

--
 
Jamie said:
Good point. Substitute "some interested parties", which encompasses
database designers (you must have seen the post where people are
bothered about non-sequential values and we don't seem able to quite
ease their minds...?)

I just don't believe that because *some* people in *some* circumstances don't
want gaps translates to "never expose AutoNumbers to users because they can have
gaps". There are plenty of circumstances where people don't care about gaps and
each situation should be looked at individually.
Are you saying you think this makes the Autonumbers suitable to expose
to end users?

Why not? Where I have used it is with records that are submitted to a
centralized database but which are generated by a few hundred external ones. In
this case the "local id" is not of great importance once the record has made it
into the central database, but if I am communicating with an external user it is
nice to be able to positively identify what record (on his end) we are talking
about and while using randomly generated AutoNumbers doesn't guarantee
uniqueness across all external users it comes close enough for my purposes (no
duplicates yet in over 5 years).

Formatting them as hex makes for a much nicer number than the longer decimal
format that would often have a negative sign. To most users the hex value
resembles a serial number since it contains digits and letters and as stated, in
the vast majority of cases they end up eight characters long which I feel is
reasonable for everyone to deal with. It is obvious to all what the field's
purpose is, to identify each record uniquely, but with no expectations about
sequences or gaps.
 

Time does not permit but take a look at the properties of a good key
to see how the imaginative and detailed (TIC) "Use a random number"
design measures up. Uniqueness (not just within the table but across
the whole domain/enterprise -- as you say, fingers crossed for no
clashes!), stability (insert the same entity's attributes into the
same/different table/database and you will get different Autonumber
values), familiarity (if every online service I use issued me with a
hex number to authenticate myself there is no way I'd remember them
all), validation (at least add a check digit!), verifiability (if the
same attributes can generate different values then the generated
values simply cannot be verified -- you can't even verify that the
values are random e.g. I had problems back in the year 2000 when I was
employee number 2000 and the personnel department had difficulty
believing the coincidence), simplicity (yes!), existence of a trust
source (no!)

Jamie.

--
 
Jamie said:
Time does not permit but take a look at the properties of a good key
[snip irrelevent key stuff]

Jamie, the topic "should AutoNumbers be exposed to users?" and "do AutoNumbers
make good primary keys?" are completely different! Everything you say about
"keys" is true of AutoNumbers whether the user sees them or not. I would expect
any competent developer to do all of the other proper stuff like enforcing
uniqueness on other data fields so as to prevent duplication of data. That is a
different area of discussion.

My point is that there are cases where AutoNumbers (or other surrogate values)
ARE used as Primary Keys or record identifiers and in those cases it is not
*universally* true that exposing them to the user is a bad thing or will cause
problems. Rather then adhering to some strict dogma one should evaluate each
situation. The following are all true...

One should not use a byte if one needs values greater than 255.

One should not use an integer if one needs fractional values.

One should not use an AutoNumber if they don't want gaps.

Despite all of those being true I still use bytes and integers when they meet my
needs and I would use an AutoNumber AND let the user see it if there was nothing
in the design spec dictating that it would be inappropriate to do so.
 
I thought about using the auto numbering because someone recommend me to say
away from that. I thought that would be an easy thing. I haven't done an
access database in 5 years. It's really showing. I need a book but the
weathers really bad here today! So, I'm stuck at home trying to find crap
online for help! Thank you for responding. I appreciate your advice and time!


Why do you want "crap" for help?
 
Jamie, the topic "should AutoNumbers be exposed to users?" and "do AutoNumbers
make good primary keys?" are completely different!

Agreed.

I consider all these to be distinct topics:

1) keys in relational theory,
2) primary keys in relational theory (deprecated),
3) artificial keys in databases,
4) surrogate keys in databases,
5) PRIMARY KEY in the SQL language,
6) PRIMARY KEY in the Jet product,
7) Autonumber in the Jet product.

My point was nothing to do with 2, 4, 5 nor 6; rather, it was whether
Jet Autonumbers (7) are suitable for use as artificial keys (1 and 3)?
I say no.
I would expect
any competent developer to do all of the other proper stuff like enforcing
uniqueness on other data fields so as to prevent duplication of data.

The point (John Vinson's) I was responding to was about a scenario
where all the available attributes do not provide a unique key...
Everything you say about
"keys" is true of AutoNumbers whether the user sees them or not.

....so if in the abovementioned scenario one is using an AutoNumber as
an artificial key then one *must* expose it, otherwise there's no
point in having it. Further, I don't think any flavour of Autonumber
is suitable for the human eye. I've no argument against an Autonumber
which nobody sees (e.g. Codd's description of a surrogate key i.e. not
visible even to database developers/DBAs).
Rather then adhering to some strict dogma one should evaluate each
situation.

Are you saying that we shouldn't have "rules of thumb" because there
might - shock horror - be exceptions to the rule?
The following are all true...

Oh yeah...?
One should not use a byte if one needs values greater than 255.

What about using the negative range of byte for extra 'headroom'?
Anyhow, I'd always use INTEGER (Long) in place of byte because it is
more portable.
One should not use an integer if one needs fractional values.

Some people use an integer type to scale their own decimal (e.g.
storing integer seconds rather than decimal hours). Me, I'd use
DECIMAL which, again, ports well. Some people say one should use
CURRENCY for up to four decimal places otherwise a floating point type
(usually FLOAT) because DECIMAL is somehow evil whereas I prefer the
fixed point DECIMAL wherever possible (as does Jet natively <g>) and
other people say other things but then that's the nature of
discussion...
One should not use an AutoNumber if they don't want gaps.

Isn't that a bit like saying, "One should not use an AutoNumber if
they don't want duplicate values" because there is nothing inherent in
Jet's AutoNumber functionality that guarantees uniqueness? If the
following can make an AutoNumber suitable if they don't want
duplicates...

CREATE TABLE Test (
ID IDENTITY(1, 1) NOT NULL PRIMARY KEY,
data_col INTEGER NOT NULL
);

....then it would follow that something like this would make AutoNumber
suitable if they don't want gaps...

CREATE TABLE Test (
ID IDENTITY(1, 1) NOT NULL PRIMARY KEY,
data_col INTEGER NOT NULL,
CONSTRAINT test__ID__no_gaps
CHECK (NOT EXISTS (
SELECT *
FROM Sequence AS S1
WHERE S1.Seq BETWEEN (SELECT MIN(T2.ID) FROM Test AS T2)
AND (SELECT MAX(T2.ID) FROM Test AS T2)
AND NOT EXISTS (
SELECT *
FROM Test AS T1
WHERE S1.Seq = T1.ID
)))
);

....where Sequence is a table of integers (seq), being a 'standard
issue' auxiliary table.

Perhaps a better assertion would have been, "One should not use an
incremental AutoNumber if they want to be able to UPDATE its values."

Jamie.

--
 
Back
Top