473,421 Members | 1,500 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

Combine two fields into another field within SAME table

I have a table [Consolidated] which lists employees. The SSN used to be used as the primary key (it was legal, given it was a government database), but now I want to delete that field and replace it with a new primary key. I have fields [LName] [FName] [MI] and [Last4] among several others. [Last4] refers to the last 4 digits of their SSN.

I want to create a new field in the SAME table [Consolidated] that combines the [LName] and [Last4] fields, creating a unique identifier that is easy to remember. Example: [LName] = "Smythe" and [Last4] = "3434". The new [EmpID] would generate "Smythe3434" or maybe "SMYT3434" (First 4 letters of last name and Last4).

Any advice on how to have [EmpID] automatically generate upon filling in [LName] and [Last4]?

I want to do this because:

Using only the [Last4] would generate duplications after 9,999 people. My database won't ever have that many people, so this is unlikely to happen, but possible.

Obviously, I don't want to use only [LName], as I already have four pairs of individuals with the same last name.

But two people having exactly the same last name and the same last 4 of SSN is HIGHLY unlikely. Using this format is something that comes naturally to employees, as many of the websites they access requires a similar format for their userid. But I have never done this within this database. It is time for it to be done.
Oct 5 '11 #1
14 8118
NeoPa
32,556 Expert Mod 16PB
It would need to be done within a Form of course, but the setup would be something like :

Use AfterUpdate event procedures on all the controls that maintain the fields that you want to be used to make up your PK. Each event procedure would call a separate procedure that builds up the composite value from the subordinate parts and checks that there is a valid result. The record should not be allowed to be saved when the status is not valid. Otherwise, the control used to represent the new PK field should be updated to the valid result.
Oct 5 '11 #2
Stewart Ross
2,545 Expert Mod 2GB
Although it is easy enough to concatenate two fields to do what you ask I would be sceptical about the result really being unique. A primary key must in all circumstances be unique. I doubt very much that the combination you describe is anything like unique - the last four digits of the SSN will be duplicated by chance in at least 1 in 10,000 records. If this duplication occurs for records of persons with common names such as Smith, Jones and so on the combination is not likely to be a true candidate key.

Anyhow, in the query designer you can enter something like this to create the concatenated result:

Expand|Select|Wrap|Line Numbers
  1. NotReallyACandidateKey: [LName] & [Last4]
Or if you want to restrict the name to just four characters (in which case it will be a certainty that you will face duplicates sooner or later) you could use:

Expand|Select|Wrap|Line Numbers
  1. EvenWorseNotACandidateKey: UCase(Left([LName], 4)) & [Last4]
As you may gather from what I've said above, I really think you need to reconsider what constitutes a candidate key in this case.

-Stewart

PS I had not seen your post # 3 (or NeoPa's response Post # 4) when I wrote this. You clearly recognise that the components of your candidate key are not unique. I disagree iwth you about the chances of occurrence of a non-unique key being consequently low - you can bet it will happen sometime, and what then? You will not be able to store the record concerned.
Oct 5 '11 #3
My database, at any given time, contains data on about 100 current employees. I also maintain the data on past employees for a period of two years, so about another 150 to 200. After 2 years, they are deleted.

Thus, there will be a maximum of about 300 employees' data contained within the database. The chances of duplicated last 4 digits of SSN, as you stated, Stewart, is 1:10,000 and I don't know the "chances" of duplicated last name. I know that I have had duplicate last names before...I currently have 4 pairs of exact same last names, and we are about to have a 5th pair. But what are the chances of two "Jones", "Smith", "Brown", etc, sharing the same last 4? I would venture to say at LEAST 1:40,000 (I bet it would be MUCH higher, like 1:100,000 or more).

Assuming those chances were exactly 1:40,000 and my database contains 300 records, I would have to use the same pair of names 133 times before I tempted fate enough for the pair to have the same last 4. Assuming that once every 5 years we got a new person in with the last name "Smith" (in reality, it hasn't been as common as one might think), it would take well over 500 years of getting a new "Smith" before I chanced getting two people named "Smith" with the same last 4. Before that happens, we will have another database mandated for use (it's already in development). This is just a database that will tie us over for the next 5 years, maybe up to a decade, while they complete the database, test it out, mandate its use, and different agencies across the board actually put it to use.

I do agree that, put to use long enough, or if I was maintaining a database with thousands of records instead of only a few hundred, the chances of occurence would be much higher. But (and I didn't state it in my original post), there really aren't a whole lot of records.

Maybe to lessen the chance of duplication even further, I will include last name, 1st 3 characters of first name, and last 4. That should raise the chances of duplication to at least 1:300,000, which is much larger than the entire agency worldwide.

I would NOT use this format on a larger database. I don't even like using it in this instance. But the people USING this database insist on an easy setup like this. They are extremely database illiterate...and that is pretty bad coming from me. I would consider myself a "fairly experienced novice". Been working with Access for about 7 years, but mostly simpler designs. Over the last year, I've been getting into more and more complicated design. But for me to call them DB illiterate, I mean they haven't designed anything more than a spreadsheet. When you explain anything DB to them, they drool!

Your thoughts, Stewart?
Oct 6 '11 #4
NeoPa
32,556 Expert Mod 16PB
In the OP it mentions employees, but it shortly afterwards mentions that it's a government database which leads one to think in terms of the whole population. I suspect (and Stewart can correct me if I've misfired) that he was thinking more along those lines when he offered his good advice on preparing for uniqueness. It's certainly something we find many members haven't considered adequately.

In this case, and particularly in view of your fuller description of your situation, it seems like you have given more than adequate consideration to the issue and have covered all your requirements appropriately.
Oct 6 '11 #5
Yes I said government to indicate that it was for a government agency. Private company computer applications are required to fit within certain rules (especially when dealing with privacy act data), while some government applications are allowed certain leeway if protective measures are used.

So I made sure to indicate government, as I have asked this question on other boards, and people answered "you're not supposed to use SSN" without answering my question.

I have created the query that combines the last name and last 4, and it work well (thank you, Stewart). What I cannot figure out is how to then apply the new concatenated data from the query onto the form, thus inputting it into the table's PK field.
Oct 6 '11 #6
NeoPa
32,556 Expert Mod 16PB
This question was essentially double-posted as AfterUpdate to populate field after data entry into two other fields. This is not allowed and the other (newer) thread has now been locked to further posting. Members involved in both threads can continue their discussions here, in one place.
Oct 6 '11 #7
patjones
931 Expert 512MB
I'm going to respond in this thread since it's what the other experts have been responding to.

As I mentioned previously, when the concatenated value appears in the third text box, you need to check in the table for that value using, for instance, the DLookup( ) function. If DLookup( ) returns null, then the value is not in the table and you need to add it. For instance:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO Consolidated(LName, Last4, EmpID) VALUES ('" & Me.txtLastName & "','" & Me.txtLast4 & "','" & Me.txtEmpID & "'")

Note that I made up the names of your text boxes: txtLastName, txtLast4, txtEmpID. You have to change those to whatever you have them named as.
Oct 6 '11 #8
NeoPa
32,556 Expert Mod 16PB
I've been somewhat busy tidying things up, but now I'm finished I'd like to outline an approach for you that should cover everything neatly. This is not a very straightforward situation, so needs some careful thinking :
  1. Change the design of your table to include an extra field that will (later) be used as the PK. For now it is a simple, unindexed, field (I'll refer to it in here as [NewPK]).
  2. Design a form that implements the requirement to create the value of this new field in the bound control on the form from two other controls (Post #2 details this for you).
  3. Run an UPDATE query to ensure all existing records in the table have PK data in the new field :
    Expand|Select|Wrap|Line Numbers
    1. UPDATE [Consolidated]
    2. SET    [NewPK] = UCase(Left([LName], 4) & Right([SSN], 4))
  4. Enable the new field as the PK.
Oct 6 '11 #9
OldBirdman
675 512MB
You underestimate the chances that you will have duplicates. True that if the last names match, the chances that the Last4 will also match is 1:10000. However the 3rd identical last name may match either the first or the second Last4 with a probability of 2:10000. If the 4th match has a probability of 3:10000 of matching one of the first 3, then for four identical last names, the probability of a match is 6:10000.
This probability is still small, but not impossible. If it should occur, your database may fail, or divulge privileged information that could get to the wrong person.
I, personally, would not take this chance.
Oct 6 '11 #10
patjones
931 Expert 512MB
Why not just use an encrypted version of the full SSN?
Oct 6 '11 #11
NeoPa
32,556 Expert Mod 16PB
See post #4 for that Pat. Near the bottom.
Oct 6 '11 #12
ok, Didn't see what NeoPa said, so going to try it out. I'll update with progress soon.
Oct 6 '11 #13
NeoPa
32,556 Expert Mod 16PB
Understandable. It was a busy period for posting it seems. We'll catch your response later.
Oct 6 '11 #14
patjones
931 Expert 512MB
I work for a large NYC government agency and got curious about this last name/last 4 situation. I just did a DB2 run and found that out of 8,681 active employees - we have eight sets of duplicate last name/last 4 combinations (two occurrences in each set)...about a 0.2% occurrence rate.
Oct 7 '11 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joey P | last post by:
Hi all, I am doing a project for university whereby i have to implement a simple database related to a frozen foods company. I am having some trouble though creating a validation rule for one...
2
by: Wayne Aprato | last post by:
I posted this yesterday and it seems like a moderator has thrown it in another thread. This is a totally different question to the one asked in that thread, so I'm posting it again. It is not a...
0
by: Ray Holtz | last post by:
Is it possible to autofill a field based on what is entered into another field in a form? My form has an employee field, and department field. In an Items Table, I have fields FldEmployee, and...
9
by: geronimo_me | last post by:
Hi, I am atempting to compare part of a field with the whole of another field in access. Is this possible? Basically I have 2 tables with the following info: Table1 Field1 = MR.
0
by: Bennett Haselton | last post by:
It seems whenever I add a new field to a database table that's queried by DataAdapters in my project, I get run-time errors because I don't go back and re-generate all the DataAdapters to read the...
4
by: hazz | last post by:
I am having a very difficult time with what should be an easy task. I simply want to select these fields from the database table into the GridView control and have checkboxes appear for which the...
2
by: brino | last post by:
i am trying to combine 2 text fields into the one field in a query. eg. "barry" & "allen" into another field so that it is "barry allen" how can i do this , ive tried a number of ways but cant...
17
by: amanda27 | last post by:
Can anyone help me. I have a database that has a form. On the form I have a subform that brings in some data that is relevant to the data on the main form but from a week before (status of projects...
2
by: zufie | last post by:
How would I transfer the values from my WorkPhone field to my CellPhone field within the same table IBCCP Referral? Thanks!, John
1
by: Totti | last post by:
Hello, I am new to MS Access (2007) and am trying to create a hyperlink in a table to Google maps without much luck. The URL I need to use in my hyperlink is...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.