473,548 Members | 2,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query to delete duplicate records in staging table

ms
Access 2000:
I am trying to delete duplicate records imported to a staging table leaving one
of the duplicates to be imported into the live table. A unique record is based
on a composite key of 3 fields (vehicleID, BattID, and ChgHrs). VehicleID and
BattID are a TEXT datatype and ChrHrs are a number(long int.) datatype. Since
records to be imported can have duplicate records of the composite key I need to
clean all but one of the duplicate records before importing into the live table.
I import the records using an import specification file.

Thank you,
mark

Nov 12 '05 #1
2 4978
DFS
"ms" <ms@nospam.comc ast.net> wrote in message
news:6s******** ************@co mcast.com...
Access 2000:
I am trying to delete duplicate records imported to a staging table leaving one of the duplicates to be imported into the live table. A unique record is based on a composite key of 3 fields (vehicleID, BattID, and ChgHrs). VehicleID and BattID are a TEXT datatype and ChrHrs are a number(long int.) datatype. Since records to be imported can have duplicate records of the composite key I need to clean all but one of the duplicate records before importing into the live table. I import the records using an import specification file.

Thank you,
mark

The Find Duplicates query wizard might help, but it's not even needed -
unless you just want to see which records are duplicated.

* If you do the insert via the db.Execute method in code it will insert the
valid records, but give you no indication any dupes failed to insert.

* If you execute an append query from the query window, it will tell you how
many dupes could not be inserted, and it will insert the records meeting the
primary key (and other validation constraints).

* You could set the same pk on your staging table, so no dupes can get in
there. Depends on how the data is coming in, and if you need to examine it
first.

Nov 12 '05 #2
ms
Thank you.
I am inserting the data using an import specif. file and this:

'Import Raw text to stageChargeLog table.
DoCmd.TransferT ext acImportFixed, "BMIDLog Link Specification", stageBMIDLog", file

Then I run a query to replace recs from stage table to live table:
CurrentDb.Query Defs("CleanDups _stageBMIDLog") .Execute

QUERY:
DELETE stageBMIDLog.*
FROM BMIDLog INNER JOIN stageBMIDLog ON (BMIDLog.BattID = stageBMIDLog.Ba ttID)
AND (BMIDLog.Vehicl eID = stageBMIDLog.Ve hicleID) AND (BMIDLog.TotalC hgAhs =
stageBMIDLog.To talChgAhs);

but it fails and gives me a msg saying: "Could not delete from specified
tables". What I don't understand is that the same query as a select statement
returns the records I want to delete. What am I missing?

DFS wrote:
"ms" <ms@nospam.comc ast.net> wrote in message
news:6s******** ************@co mcast.com...
Access 2000:
I am trying to delete duplicate records imported to a staging table


leaving one
of the duplicates to be imported into the live table. A unique record is


based
on a composite key of 3 fields (vehicleID, BattID, and ChgHrs). VehicleID


and
BattID are a TEXT datatype and ChrHrs are a number(long int.) datatype.


Since
records to be imported can have duplicate records of the composite key I


need to
clean all but one of the duplicate records before importing into the live


table.
I import the records using an import specification file.

Thank you,
mark


The Find Duplicates query wizard might help, but it's not even needed -
unless you just want to see which records are duplicated.

* If you do the insert via the db.Execute method in code it will insert the
valid records, but give you no indication any dupes failed to insert.

* If you execute an append query from the query window, it will tell you how
many dupes could not be inserted, and it will insert the records meeting the
primary key (and other validation constraints).

* You could set the same pk on your staging table, so no dupes can get in
there. Depends on how the data is coming in, and if you need to examine it
first.


Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
10305
by: Pawel Banys | last post by:
Hello, There is a program which performs some scripted actions via ODBC on tables in some database on mssql 2000. Sometimes that program tries to insert record with key that is already present in the database. The error comes up and the program stops. Is there any way to globally configure the database or the whole mssql server to ignore...
3
2401
by: Alexander Anderson | last post by:
I have a DELETE statement that deletes duplicate data from a table. It takes a long time to execute, so I thought I'd seek advice here. The structure of the table is little funny. The following is NOT the table, but the representation of the data in the table: +-----------+ | a | b | +-----+-----+ | 123 | 234 | | 345 | 456 |
4
2241
by: starman7 | last post by:
I have a query that seems to kill the db for our website (causes the 'Too many connections' error). I would like to avoid this! Is there a way to test the query before the db goes down? I do not have access to a staging environment. I can access the db via Linux command line, or phpMyAdmin - however I can only select, update, and delete. ...
16
4160
by: tyrfboard | last post by:
I've been searching for awhile now on how to remove duplicates from a table within an Access db and have found plenty of articles on finding or deleting duplicates. All I want to do is remove them from within an SQL query - leaving one of the records behind of course. I have a mailing list comprised of a union query that gets records from...
1
2013
by: JC | last post by:
Hello, I am trying to change a select, find duplicates, query into a delete query. I want to get rid of the records in the main table "tblHurnsHistory." I changed the Find Duplicates query to a Delete query. I then received an input box looking for criteria that states," Enter parameter value qryHurnsHistory.Grads_creditsEarned
16
3473
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate...
1
1891
by: bcquadrant | last post by:
Hi there I am trying to make an update query that will update information in all occurances of duplicate records based on the First record for that duplicate set. There are about 30,000 records in the table, and of them without the duplicates there is only about 4000 records.The duplicates are essential to work we do, so we cannot delete...
6
5921
by: Dilip1983 | last post by:
Hi All, I want to delete duplicate records from a large table. There is one index(INDEX_U1) on 4 columns(col1,col2,col3,col4) which is in unusable state. First of all when i tried to rebuild index it showed error as unique key violation. So i want to delete duplicate records for col1,col2,col3,col4 combination. How can i delete the...
1
1889
by: DontTell | last post by:
Hi - I am trying to delete duplicate records from a single table. The table has multilple records of duplicate purchase orders. In these instances I need to delete those records that have the same $amt but different qty. I have already created the delete query but am unsure how to specify the criteria which should be based on the $amt and...
0
7438
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7803
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6036
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.