Question

Conditional Update Query

Asked by: christie_holtz

Here is the situation.  
My HR database uses SSN as the primary key.  However, due to new regulations, SSN cannot be in a database.  I have to keep those SSN though because I have other fields that are linked to this field.  My HR department created new Employee Numbers, randomly.  I need to have these numbers as the new Employee# (primary key), but also keep an archived column in that table with the SSN numbers.  I initially set up an update query that automatically ran whenever the database opened, which made the Employee # (primary key) equal to a new field called EmployeeID.  However, once the new numbers are entered in, the query will just duplicate the new numbers, thus bumping out the SSN.  Is there anyway that a conditional update query can be written?  Can you think of anything else that could be done to fix this problem?  Am I totally off base?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-02-10 at 10:17:13ID20880011
Tags

update

,

conditional

,

query

Topic

Microsoft Access Database

Participating Experts
3
Points
500
Comments
33

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. ADUC Find... based on employeeID attribute.
    Hi all, I am trying to accomplish some queries in Active Directory, and I was wondering as to whether it was possible. here's my scenario. I have implemented the employeeID attribute in my environment, as it is a unique ID across my enterprise. I am trying to create a smal...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: capricorn1Posted on 2004-02-10 at 10:24:22ID: 10324587

did you set the employee# to no duplicates?

 

by: capricorn1Posted on 2004-02-10 at 10:25:49ID: 10324598

<<However, once the new numbers are entered in, the query will just duplicate the new numbers, thus bumping out the SSN. >>

Please give more explanation to the above line.

 

by: christie_holtzPosted on 2004-02-10 at 10:28:13ID: 10324627

Employee# is the primary key, so there are no duplicates.

 

by: christie_holtzPosted on 2004-02-10 at 10:29:58ID: 10324647

I meant, if I just used a plain update query:
UPDATE StaffTest SET StaffTest.EmployeeID = [Employee#];
 Then whenI put in the new Randomly assigned Employee#, the SSN will be totally erased...
does this clear it up?

 

by: kmslogicPosted on 2004-02-10 at 10:30:12ID: 10324648

Hi christie_holtz,

You're going to need a mapping table with two columns, Employee ID and SSN.  The first step will be to fill this table with every SSN in your system and a corresponding employee ID.  Once that is done add (if it doesn't exist yet) an employee ID field to all of your tables that need it and use the map table to update them based on the SSN they contain.  Then remove the SSN field from all tables and adjust your key to include the EmployeeID field.

And it goes without saying that you'll need a backup or two before you do this.


Kelly

 

by: christie_holtzPosted on 2004-02-10 at 10:31:23ID: 10324659

I intend to create a new field to house SSN for old employees called EmployeeID, then for new employees just have the EmployeeID equal their Employee#

 

by: christie_holtzPosted on 2004-02-10 at 10:35:24ID: 10324701


Will the mapping table work if I need the  fields to equal below:

For old new employees
Employee#=Newly Assigned Random Number
EmployeeID=SSN

For new employees
Employee#=New Assigned Random Number
EmployeeID=The same newly assigned random number

 

by: capricorn1Posted on 2004-02-10 at 10:37:29ID: 10324724

That is the reason why the SSN is getting erased. (SSN)EmployeeID
UPDATE StaffTest SET StaffTest.EmployeeID = [Employee#];
You are replacing the SSN with Employee#

 

by: christie_holtzPosted on 2004-02-10 at 10:41:05ID: 10324767

I don't want SSN totally erased though.  I wanted to hide the column

 

by: christie_holtzPosted on 2004-02-10 at 10:48:28ID: 10324844

Anyone?

 

by: capricorn1Posted on 2004-02-10 at 11:04:59ID: 10324993

You need a new field on your tables for Employee#
With the mapping table that Kelly suggested you can run a query to update all your tables.
The mapping table should have Employee# and EmployeeID as fields with EmployeeID holding the SSN

UPDATE StaffTest SET StaffTest.Employee# = [MappingTable.Employee#] Where StaffTest.EmployeeID=MappingTable.EmployeeID;

 

by: kmslogicPosted on 2004-02-10 at 11:08:15ID: 10325032

I guess I'm unclear about your overall objective.  In your post you said it was illegal to have SSN in your database but you still want to retain the field?  How does this work exactly?

 

by: christie_holtzPosted on 2004-02-10 at 11:15:29ID: 10325130

I am getting an error when I execute the following SQL statement
UPDATE StaffTest SET StaffTest.Employee# = [MappingTable.Employee#] Where StaffTest.EmployeeID=MappingTable.EmployeeID;

 

by: christie_holtzPosted on 2004-02-10 at 11:18:41ID: 10325167

I know...it is a very confusing request.  I need to keep the SSN number in the database, but just have the column hidden.

 

by: capricorn1Posted on 2004-02-10 at 11:43:32ID: 10325420

what error are you getting?

 

by: christie_holtzPosted on 2004-02-10 at 11:52:20ID: 10325511

Syntax error in Update Statement....then when I press ok the cursor goes to the # on the first Employee#

 

by: capricorn1Posted on 2004-02-10 at 11:53:10ID: 10325522

We have to replace that character with No

 

by: christie_holtzPosted on 2004-02-10 at 11:55:09ID: 10325541

Let me try that!

 

by: kmslogicPosted on 2004-02-10 at 11:56:45ID: 10325558

UPDATE StaffTest SET StaffTest.Employee# = [MappingTable].[Employee#] Where StaffTest.EmployeeID=MappingTable.EmployeeID;

 

by: christie_holtzPosted on 2004-02-10 at 11:56:52ID: 10325562

Got another error...Invalid bracketing of name '[MappingTable.EmployeeNo]'

 

by: kmslogicPosted on 2004-02-10 at 11:57:15ID: 10325567

UPDATE StaffTest SET [StaffTest].[Employee#] = [MappingTable.Employee#] Where StaffTest.EmployeeID=MappingTable.EmployeeID;

 

by: kmslogicPosted on 2004-02-10 at 11:57:42ID: 10325577

crud!

UPDATE StaffTest SET [StaffTest].[Employee#] = [MappingTable].[Employee#] Where StaffTest.EmployeeID=MappingTable.EmployeeID;

 

by: kmslogicPosted on 2004-02-10 at 11:59:56ID: 10325605

Hopefully when this question is closed the admins can clean all those posts up.  The bottom line is that because you have a 'bad' character in your field name (the 3 sign) you need to bracket the table and the field with square braces.  You can't do this: [mytable.myfield#] but you can do this: [mytable].[myfield#]

 

by: christie_holtzPosted on 2004-02-10 at 12:03:25ID: 10325640

Do I need to change the EmployeeNo back to Employee#?

 

by: kmslogicPosted on 2004-02-10 at 12:08:39ID: 10325686

No, it's better to use fields that don't have this conflict.  If you've changed the field name go with that!

 

by: christie_holtzPosted on 2004-02-10 at 12:15:07ID: 10325757

Ok...Here is what I am doing.  I am going to the Query section and writing a new query. In design view, I add the two tables to the query....I then go into SQL view and copy the statement, however when I go back to design view....the mappingtable is missing...so then when I try to run the query I get prompts to enter in MappingTable.Employee# and MappingTable.EmployeeID....what am I doing wrong?

 

by: capricorn1Posted on 2004-02-10 at 12:16:32ID: 10325776

The # is one of the Wildcard Characters Used in String Comparisons

 

by: christie_holtzPosted on 2004-02-10 at 12:20:50ID: 10325820

I'm sorry....I wrote it wrong....I have changed the field names to EmployeeNo

 

by: bonjour-autPosted on 2004-02-10 at 16:19:06ID: 10327992

Hi christie and capricorn1

my opinion on this matter: if it is illegal to kepp SSN, you should not keep it in the database
if you need it, because you used it as key to bind otehr records, you should try the following:

based on the saved("old") version:
1. set up links for the SSN to the other tables with referential integrity set to yes for updates
2. overwrite the SSN with newly assigned random number
so all links will be automatically updated.

3. keep a manual list for new number mapped to SSN in a safe place, so you can interpret old printouts if necessary

Regards, Franz

 

by: capricorn1Posted on 2004-02-10 at 17:01:24ID: 10328258

Thanks Franz,
Actually that is what I have in mind.

Rey:-)

 

by: kmslogicPosted on 2004-02-10 at 22:05:08ID: 10329837

Hey Franz that's what I had in mind also per my post way up there, but I think she wants to permanently keep the ssn field in the database and hide it somehow even after the links are updated.  I have to admit I'm still not clear on exactly why she wants to keep the ssn field after the links have been updated.

 

by: bonjour-autPosted on 2004-02-11 at 01:04:09ID: 10330464

Hi Rey,

Lets see, what Christie makes of it. If there is no technical necessety, she should not  keep it. Keeping the mapping of new nuber to ssn as extra-file should be sufficent. You can import it as table with a click, if you need it for some reason in the future.

if for organisational reasons, she will need it in the application, she wiill need to personalize and secure the usage of the mdb, so only specaily privileged users will be able to see this form. of corse in this case the mapping will have to be held in an extra table, so you can secure this table also.

Regards, Franz

 

by: christie_holtzPosted on 2004-02-11 at 09:21:48ID: 10334175

With all of your help, I have actually come up with something.  I created an AutoExec marco which ran a SQL statement which updated only specific employee numbers...after adding an autonumber as a counting device.  The SQl statement updates Employee#=EmployeeID only if the Employee# is >356 (the current number of employees)....otherwise Employee# is a newly assigned random number and EmployeeID is SSN.....

I understand this was logically a tough request...and I agree...I don't understand HR insists on keeping SSN....

Thanks

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...