A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

comparing two tables



 
 
Thread Tools Display Modes
  #1  
Old February 13th, 2007, 05:52 PM posted to microsoft.public.access.queries
imranmp
external usenet poster
 
Posts: 7
Default comparing two tables

Hi,
I want to compare records from two tables:
TempTable - has all the records that i have imported, i want to check if
there are any new records that do not already exist in tblDataFile; if it
finds a repeat record then delete from TempTable

am trying to use the below query... what am i doing wrong? is there a better
way?

Do While tblDataFile EOF
DoCmd.RunSQL "DELETE * FROM TempTable WHERE TempTable.F2 =
tblDataFile.Date AND TempTable.F1 = tblDataFile.County"
Loop

thanks
  #2  
Old February 13th, 2007, 06:50 PM posted to microsoft.public.access.queries
kingston via AccessMonster.com
external usenet poster
 
Posts: 620
Default comparing two tables

What exactly is the relationship between the data table and the temp table?
In other words, where did the data come from for the temp table? What is
your code not doing that you expect it to do? I assume that this code is
just representative of your logic and you know you need to advance the record
in the tblDataFile recordset:

tblDataFile.MoveNext


imranmp wrote:
Hi,
I want to compare records from two tables:
TempTable - has all the records that i have imported, i want to check if
there are any new records that do not already exist in tblDataFile; if it
finds a repeat record then delete from TempTable

am trying to use the below query... what am i doing wrong? is there a better
way?

Do While tblDataFile EOF
DoCmd.RunSQL "DELETE * FROM TempTable WHERE TempTable.F2 =
tblDataFile.Date AND TempTable.F1 = tblDataFile.County"
Loop

thanks


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200702/1

  #3  
Old February 13th, 2007, 07:16 PM posted to microsoft.public.access.queries
George Nicholson
external usenet poster
 
Posts: 791
Default comparing two tables

No need for Loop.

strSQL = "DELETE * FROM TempTable
INNER JOIN tblDataFile ON (TempTable.F2 =
tblDataFile.Date) AND (TempTable.F1 = tblDataFile.County)"

DoCmd.RunSQL strSQL

(or)
CurrentDb.Execute strSQL, dbFailOnError

HTH,

"imranmp" wrote in message
...
Hi,
I want to compare records from two tables:
TempTable - has all the records that i have imported, i want to check if
there are any new records that do not already exist in tblDataFile; if it
finds a repeat record then delete from TempTable

am trying to use the below query... what am i doing wrong? is there a
better
way?

Do While tblDataFile EOF
DoCmd.RunSQL "DELETE * FROM TempTable WHERE TempTable.F2 =
tblDataFile.Date AND TempTable.F1 = tblDataFile.County"
Loop

thanks



  #4  
Old February 13th, 2007, 08:50 PM posted to microsoft.public.access.queries
imranmp
external usenet poster
 
Posts: 7
Default comparing two tables

thanks for the quick reply...
using your code i am getting an error saying "specify the table containing
the records you want to delete"

any ideas?

"George Nicholson" wrote:

No need for Loop.

strSQL = "DELETE * FROM TempTable
INNER JOIN tblDataFile ON (TempTable.F2 =
tblDataFile.Date) AND (TempTable.F1 = tblDataFile.County)"

DoCmd.RunSQL strSQL

(or)
CurrentDb.Execute strSQL, dbFailOnError

HTH,

"imranmp" wrote in message
...
Hi,
I want to compare records from two tables:
TempTable - has all the records that i have imported, i want to check if
there are any new records that do not already exist in tblDataFile; if it
finds a repeat record then delete from TempTable

am trying to use the below query... what am i doing wrong? is there a
better
way?

Do While tblDataFile EOF
DoCmd.RunSQL "DELETE * FROM TempTable WHERE TempTable.F2 =
tblDataFile.Date AND TempTable.F1 = tblDataFile.County"
Loop

thanks




  #5  
Old February 13th, 2007, 09:29 PM posted to microsoft.public.access.queries
imranmp
external usenet poster
 
Posts: 7
Default comparing two tables

tblDataFile and TempTable have exactly same structure(fields and types)
TempTable has data(new and old) which was imported form a CSV file; I want
to list all the new records. thats why i want to compare the TempTable and
the tblDataFile and delete all the records that are already existing in
tblDataFile... i check if the record exists by cheking the combination of
date and county fields
thanks


"kingston via AccessMonster.com" wrote:

What exactly is the relationship between the data table and the temp table?
In other words, where did the data come from for the temp table? What is
your code not doing that you expect it to do? I assume that this code is
just representative of your logic and you know you need to advance the record
in the tblDataFile recordset:

tblDataFile.MoveNext


imranmp wrote:
Hi,
I want to compare records from two tables:
TempTable - has all the records that i have imported, i want to check if
there are any new records that do not already exist in tblDataFile; if it
finds a repeat record then delete from TempTable

am trying to use the below query... what am i doing wrong? is there a better
way?

Do While tblDataFile EOF
DoCmd.RunSQL "DELETE * FROM TempTable WHERE TempTable.F2 =
tblDataFile.Date AND TempTable.F1 = tblDataFile.County"
Loop

thanks


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/200702/1


  #6  
Old February 13th, 2007, 10:26 PM posted to microsoft.public.access.queries
George Nicholson
external usenet poster
 
Posts: 791
Default comparing two tables

My bad. Change to:

"DELETE TempTable.* FROM TempTable....



"imranmp" wrote in message
...
thanks for the quick reply...
using your code i am getting an error saying "specify the table containing
the records you want to delete"

any ideas?

"George Nicholson" wrote:

No need for Loop.

strSQL = "DELETE * FROM TempTable
INNER JOIN tblDataFile ON (TempTable.F2 =
tblDataFile.Date) AND (TempTable.F1 = tblDataFile.County)"

DoCmd.RunSQL strSQL

(or)
CurrentDb.Execute strSQL, dbFailOnError

HTH,

"imranmp" wrote in message
...
Hi,
I want to compare records from two tables:
TempTable - has all the records that i have imported, i want to check
if
there are any new records that do not already exist in tblDataFile; if
it
finds a repeat record then delete from TempTable

am trying to use the below query... what am i doing wrong? is there a
better
way?

Do While tblDataFile EOF
DoCmd.RunSQL "DELETE * FROM TempTable WHERE TempTable.F2 =
tblDataFile.Date AND TempTable.F1 = tblDataFile.County"
Loop

thanks






  #7  
Old February 14th, 2007, 02:15 PM posted to microsoft.public.access.queries
imranmp
external usenet poster
 
Posts: 7
Default comparing two tables

Still getting an error: Could Not delete from specified tables.


"George Nicholson" wrote:

My bad. Change to:

"DELETE TempTable.* FROM TempTable....



"imranmp" wrote in message
...
thanks for the quick reply...
using your code i am getting an error saying "specify the table containing
the records you want to delete"

any ideas?

"George Nicholson" wrote:

No need for Loop.

strSQL = "DELETE * FROM TempTable
INNER JOIN tblDataFile ON (TempTable.F2 =
tblDataFile.Date) AND (TempTable.F1 = tblDataFile.County)"

DoCmd.RunSQL strSQL

(or)
CurrentDb.Execute strSQL, dbFailOnError

HTH,

"imranmp" wrote in message
...
Hi,
I want to compare records from two tables:
TempTable - has all the records that i have imported, i want to check
if
there are any new records that do not already exist in tblDataFile; if
it
finds a repeat record then delete from TempTable

am trying to use the below query... what am i doing wrong? is there a
better
way?

Do While tblDataFile EOF
DoCmd.RunSQL "DELETE * FROM TempTable WHERE TempTable.F2 =
tblDataFile.Date AND TempTable.F1 = tblDataFile.County"
Loop

thanks






  #8  
Old February 14th, 2007, 02:28 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 2,364
Default comparing two tables

Try this

DELETE * FROM TempTable
WHERE TempTable.F2 & '///' & TempTable.F1 IN
(SELECT tblDataFile.Date & '///' & tblDataFile.County
FROM tblDataFile)

OR
DELETE * FROM TempTable
WHERE Exists
(SELECT *
FROM tblDataFile
WHERE tblDataFile.Date = TempTable.F2 AND
tblDataFile.County AND TempTable.F1)

If those fail then try adding DISTINCTROW to the DELETE clause as in
DELETE DISTINCTROW * FROM ...

================================================== ==
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
================================================== ==


imranmp wrote:
Still getting an error: Could Not delete from specified tables.


"George Nicholson" wrote:

My bad. Change to:

"DELETE TempTable.* FROM TempTable....



"imranmp" wrote in message
...
thanks for the quick reply...
using your code i am getting an error saying "specify the table containing
the records you want to delete"

any ideas?

"George Nicholson" wrote:

No need for Loop.

strSQL = "DELETE * FROM TempTable
INNER JOIN tblDataFile ON (TempTable.F2 =
tblDataFile.Date) AND (TempTable.F1 = tblDataFile.County)"

DoCmd.RunSQL strSQL

(or)
CurrentDb.Execute strSQL, dbFailOnError

HTH,

"imranmp" wrote in message
...
Hi,
I want to compare records from two tables:
TempTable - has all the records that i have imported, i want to check
if
there are any new records that do not already exist in tblDataFile; if
it
finds a repeat record then delete from TempTable

am trying to use the below query... what am i doing wrong? is there a
better
way?

Do While tblDataFile EOF
DoCmd.RunSQL "DELETE * FROM TempTable WHERE TempTable.F2 =
tblDataFile.Date AND TempTable.F1 = tblDataFile.County"
Loop

thanks




  #9  
Old February 14th, 2007, 03:16 PM posted to microsoft.public.access.queries
imranmp
external usenet poster
 
Posts: 7
Default comparing two tables

Thanks John,
The first query works but its takes too long.. almost 2 mins - and the
tables have only 5000 records; is there a way to make it faster.

The Second query is much faster but it deletes 33 records while it should
delete only 1.

thanks again

"John Spencer" wrote:

Try this

DELETE * FROM TempTable
WHERE TempTable.F2 & '///' & TempTable.F1 IN
(SELECT tblDataFile.Date & '///' & tblDataFile.County
FROM tblDataFile)

OR
DELETE * FROM TempTable
WHERE Exists
(SELECT *
FROM tblDataFile
WHERE tblDataFile.Date = TempTable.F2 AND
tblDataFile.County AND TempTable.F1)

If those fail then try adding DISTINCTROW to the DELETE clause as in
DELETE DISTINCTROW * FROM ...

================================================== ==
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
================================================== ==


imranmp wrote:
Still getting an error: Could Not delete from specified tables.


"George Nicholson" wrote:

My bad. Change to:

"DELETE TempTable.* FROM TempTable....



"imranmp" wrote in message
...
thanks for the quick reply...
using your code i am getting an error saying "specify the table containing
the records you want to delete"

any ideas?

"George Nicholson" wrote:

No need for Loop.

strSQL = "DELETE * FROM TempTable
INNER JOIN tblDataFile ON (TempTable.F2 =
tblDataFile.Date) AND (TempTable.F1 = tblDataFile.County)"

DoCmd.RunSQL strSQL

(or)
CurrentDb.Execute strSQL, dbFailOnError

HTH,

"imranmp" wrote in message
...
Hi,
I want to compare records from two tables:
TempTable - has all the records that i have imported, i want to check
if
there are any new records that do not already exist in tblDataFile; if
it
finds a repeat record then delete from TempTable

am trying to use the below query... what am i doing wrong? is there a
better
way?

Do While tblDataFile EOF
DoCmd.RunSQL "DELETE * FROM TempTable WHERE TempTable.F2 =
tblDataFile.Date AND TempTable.F1 = tblDataFile.County"
Loop

thanks





  #10  
Old February 14th, 2007, 03:21 PM posted to microsoft.public.access.queries
imranmp
external usenet poster
 
Posts: 7
Default comparing two tables

Never Mind... the second query works and its quick.. there was a typo
tblDataFile.County AND TempTable.F1)

needs to be
tblDataFile.County = TempTable.F1)



"John Spencer" wrote:

Try this

DELETE * FROM TempTable
WHERE TempTable.F2 & '///' & TempTable.F1 IN
(SELECT tblDataFile.Date & '///' & tblDataFile.County
FROM tblDataFile)

OR
DELETE * FROM TempTable
WHERE Exists
(SELECT *
FROM tblDataFile
WHERE tblDataFile.Date = TempTable.F2 AND
tblDataFile.County AND TempTable.F1)

If those fail then try adding DISTINCTROW to the DELETE clause as in
DELETE DISTINCTROW * FROM ...

================================================== ==
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
================================================== ==


imranmp wrote:
Still getting an error: Could Not delete from specified tables.


"George Nicholson" wrote:

My bad. Change to:

"DELETE TempTable.* FROM TempTable....



"imranmp" wrote in message
...
thanks for the quick reply...
using your code i am getting an error saying "specify the table containing
the records you want to delete"

any ideas?

"George Nicholson" wrote:

No need for Loop.

strSQL = "DELETE * FROM TempTable
INNER JOIN tblDataFile ON (TempTable.F2 =
tblDataFile.Date) AND (TempTable.F1 = tblDataFile.County)"

DoCmd.RunSQL strSQL

(or)
CurrentDb.Execute strSQL, dbFailOnError

HTH,

"imranmp" wrote in message
...
Hi,
I want to compare records from two tables:
TempTable - has all the records that i have imported, i want to check
if
there are any new records that do not already exist in tblDataFile; if
it
finds a repeat record then delete from TempTable

am trying to use the below query... what am i doing wrong? is there a
better
way?

Do While tblDataFile EOF
DoCmd.RunSQL "DELETE * FROM TempTable WHERE TempTable.F2 =
tblDataFile.Date AND TempTable.F1 = tblDataFile.County"
Loop

thanks





 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:11 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.