I have a table of employees' details, and every Monday an Excel arrives with an updated list. There is an Append Query set up to import this each week into the database, but being append, it is adding records that aren't already there, but not deleting ones that should be deleted because they will have left the organization (I'll include the code below in case it's needed). The Excel sheets received each week do not list employees who have left.
1. I want to be able to remove the records in the table that don't correspond to what is in the Excel being imported. If possible, how could I do this?
2. Is there a way of updating a particular record if the new Excel details something different for the employee (such as a Last Name or Position Name change), or would it be simpler just to replace the record each week from the new Excel, even if there has been no change to the employee details?
The Employee Number acts as the primary key and doesn't change. Thanking you in advance! :-)
INSERT INTO Employees ( [Organization Name], [Subordinate Organization], [Subordinate Cost Centre], [Employee Number], [Person Name], [Email Address], [Position Name], [Job Name], [Grade Name], [Supervisor Number], [Supervisor Name], [Hire Date], [Employment Category], [Date Of Birth], [Age (at effective date)], [National Identifier], Gender, [Working Hours], [Collective Agreement Name], [All Inclusive Salary], [Payroll Name], [Pay Group], [User Assignment Status], Title, [First Name], [Last Name], [People Group] )
SELECT [New Starters].[Organization Name], [New Starters].[Subordinate Organization], [New Starters].[Subordinate Cost Centre], [New Starters].[Employee Number], [New Starters].[Person Name], [New Starters].[Email Address], [New Starters].[Position Name], [New Starters].[Job Name], [New Starters].[Grade Name], [New Starters].[Supervisor Number], [New Starters].[Supervisor Name], [New Starters].[Hire Date], [New Starters].[Employment Category], [New Starters].[Date Of Birth], [New Starters].[Age (at effective date)], [New Starters].[National Identifier], [New Starters].Gender, [New Starters].[Working Hours], [New Starters].[Collective Agreement Name], [New Starters].[All Inclusive Salary], [New Starters].[Payroll Name], [New Starters].[Pay Group], [New Starters].[User Assignment Status], [New Starters].Title, [New Starters].[First Name], [New Starters].[Last Name], [New Starters].[People Group]
FROM [New Starters] LEFT JOIN Employees ON [New Starters].[Employee Number] = Employees.[Employee Number]
WHERE ((([New Starters].[Employee Number]) Is Not Null) AND ((Employees.[Employee Number]) Is Null));