472,352 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 4854
DFS
"ms" <ms@nospam.comcast.net> wrote in message
news:6s********************@comcast.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.TransferText acImportFixed, "BMIDLog Link Specification", stageBMIDLog", file

Then I run a query to replace recs from stage table to live table:
CurrentDb.QueryDefs("CleanDups_stageBMIDLog").Exec ute

QUERY:
DELETE stageBMIDLog.*
FROM BMIDLog INNER JOIN stageBMIDLog ON (BMIDLog.BattID = stageBMIDLog.BattID)
AND (BMIDLog.VehicleID = stageBMIDLog.VehicleID) AND (BMIDLog.TotalChgAhs =
stageBMIDLog.TotalChgAhs);

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.comcast.net> wrote in message
news:6s********************@comcast.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
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...
3
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...
4
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...
16
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...
1
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...
16
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...
1
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...
6
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...
1
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.