473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

RunSQL Delete is locking up/taking forever

Hi,

Using Access 2003.

I am trying to delete records from one table/query
("qryHistoryPersonIDs") if they don't exist in another table
("qryDonations"). But the SQL syntax I came up with is taking forever
or locking up Access 2003.

What am I doing wrong?

The code is below. dFromDate_pw and dToDate_pw are set to values of
date fields on a form. qryHistoryPersonIDs contains one key field:

DoCmd.RunSQL "Delete * From qryHistoryPersonIDs Where
qryHistoryPersonIDs.personID Not In (Select qryDonations.personid From
qryDonations Where tblDonations.[DonationDate] Not Between #" &
dFromDate_pw & "# And #" & dToDate_pw & "# )"

I'd rather not manually read through the table as it has 4,000 records
and is growing.

Any ideas?

-pw

use paulwilliamson at spamcop dot net for e-mail
Nov 16 '05 #1
8 2770
pa******************@removespamcop.net wrote:
Hi,

Using Access 2003.

I am trying to delete records from one table/query
("qryHistoryPersonIDs") if they don't exist in another table
("qryDonations"). But the SQL syntax I came up with is taking forever
or locking up Access 2003.

What am I doing wrong?

The code is below. dFromDate_pw and dToDate_pw are set to values of
date fields on a form. qryHistoryPersonIDs contains one key field:

DoCmd.RunSQL "Delete * From qryHistoryPersonIDs Where
qryHistoryPersonIDs.personID Not In (Select qryDonations.personid From
qryDonations Where tblDonations.[DonationDate] Not Between #" &
dFromDate_pw & "# And #" & dToDate_pw & "# )"

I'd rather not manually read through the table as it has 4,000 records
and is growing.

Any ideas?

-pw

use paulwilliamson at spamcop dot net for e-mail


The 'Not In (Select... syntax is known to be slow for larger tables.
If you use the wizard to create an unmatched query it will show you an
alternate syntax for returning the same records using a LEFT JOIN that
runs much faster.

James A. Fortune

Nov 16 '05 #2
On 16 Nov 2005 15:20:27 -0800, ji********@compumarc.com wrote:
pa******************@removespamcop.net wrote:
Hi,

Using Access 2003.

I am trying to delete records from one table/query
("qryHistoryPersonIDs") if they don't exist in another table
("qryDonations"). But the SQL syntax I came up with is taking forever
or locking up Access 2003.

What am I doing wrong?

The code is below. dFromDate_pw and dToDate_pw are set to values of
date fields on a form. qryHistoryPersonIDs contains one key field:

DoCmd.RunSQL "Delete * From qryHistoryPersonIDs Where
qryHistoryPersonIDs.personID Not In (Select qryDonations.personid From
qryDonations Where tblDonations.[DonationDate] Not Between #" &
dFromDate_pw & "# And #" & dToDate_pw & "# )"

I'd rather not manually read through the table as it has 4,000 records
and is growing.

Any ideas?

-pw

use paulwilliamson at spamcop dot net for e-mail


The 'Not In (Select... syntax is known to be slow for larger tables.
If you use the wizard to create an unmatched query it will show you an
alternate syntax for returning the same records using a LEFT JOIN that
runs much faster.

James A. Fortune


Hi James.

I did as you suggested and converted this (from the wizard SQL
Syntax):

SELECT tblHistoryPersonIDs.PersonID
FROM tblHistoryPersonIDs LEFT JOIN tblDonations ON
tblHistoryPersonIDs.PersonID = tblDonations.PersonID
WHERE (((tblDonations.PersonID) Is Null));

To:

DoCmd.RunSQL "Delete * From tblHistoryPersonIDs LEFT JOIN
tblDonations ON tblHistoryPersonIDs.PersonID = tblDonations.PersonID
WHERE tblDonations.[DonationDate] Not Between #" & dFromDate_pw & "#
And #" & dToDate_pw & "#"

And I am getting "Specify the table containing the records you want to
delete". Can't figure it out. Am getting sleepy ;-0

Any ideas?

-pw

use paulwilliamson at spamcop dot net for e-mail
Nov 17 '05 #3
pa******************@removespamcop.net wrote:
On 16 Nov 2005 15:20:27 -0800, ji********@compumarc.com wrote:
pa******************@removespamcop.net wrote:
Hi,

Using Access 2003.

I am trying to delete records from one table/query
("qryHistoryPersonIDs") if they don't exist in another table
("qryDonations"). But the SQL syntax I came up with is taking forever
or locking up Access 2003.

What am I doing wrong?

The code is below. dFromDate_pw and dToDate_pw are set to values of
date fields on a form. qryHistoryPersonIDs contains one key field:

DoCmd.RunSQL "Delete * From qryHistoryPersonIDs Where
qryHistoryPersonIDs.personID Not In (Select qryDonations.personid From
qryDonations Where tblDonations.[DonationDate] Not Between #" &
dFromDate_pw & "# And #" & dToDate_pw & "# )"

I'd rather not manually read through the table as it has 4,000 records
and is growing.

Any ideas?

-pw

use paulwilliamson at spamcop dot net for e-mail


The 'Not In (Select... syntax is known to be slow for larger tables.
If you use the wizard to create an unmatched query it will show you an
alternate syntax for returning the same records using a LEFT JOIN that
runs much faster.

James A. Fortune


Hi James.

I did as you suggested and converted this (from the wizard SQL
Syntax):

SELECT tblHistoryPersonIDs.PersonID
FROM tblHistoryPersonIDs LEFT JOIN tblDonations ON
tblHistoryPersonIDs.PersonID = tblDonations.PersonID
WHERE (((tblDonations.PersonID) Is Null));

To:

DoCmd.RunSQL "Delete * From tblHistoryPersonIDs LEFT JOIN
tblDonations ON tblHistoryPersonIDs.PersonID = tblDonations.PersonID
WHERE tblDonations.[DonationDate] Not Between #" & dFromDate_pw & "#
And #" & dToDate_pw & "#"

And I am getting "Specify the table containing the records you want to
delete". Can't figure it out. Am getting sleepy ;-0

Any ideas?

-pw

use paulwilliamson at spamcop dot net for e-mail


I didn't check your unmatched query, but when you get the unmatched
records the 'Not In (SELECT...' switches to 'IN (SELECT
tblHistoryPersonIDs.PersonID ...

That is, the unmatched query should return the ones that are 'Not In'
so they are now 'In.'

I explained this in:

http://groups.google.com/group/comp....63454c21472dc3

but I didn't do that great a job of explaining it there either. If
that doesn't help, post back and I'll organize my thoughts into
something a little more elegant and understandable. BTW, the ecommerce
code in that thread was from about six years ago and I cringed when I
saw it.

James A. Fortune

Nov 17 '05 #4
On 17 Nov 2005 00:02:35 -0800, ji********@compumarc.com wrote:
pa******************@removespamcop.net wrote:
On 16 Nov 2005 15:20:27 -0800, ji********@compumarc.com wrote:
>pa******************@removespamcop.net wrote:
>> Hi,
>>
>> Using Access 2003.
>>
>> I am trying to delete records from one table/query
>> ("qryHistoryPersonIDs") if they don't exist in another table
>> ("qryDonations"). But the SQL syntax I came up with is taking forever
>> or locking up Access 2003.
>>
>> What am I doing wrong?
>>
>> The code is below. dFromDate_pw and dToDate_pw are set to values of
>> date fields on a form. qryHistoryPersonIDs contains one key field:
>>
>> DoCmd.RunSQL "Delete * From qryHistoryPersonIDs Where
>> qryHistoryPersonIDs.personID Not In (Select qryDonations.personid From
>> qryDonations Where tblDonations.[DonationDate] Not Between #" &
>> dFromDate_pw & "# And #" & dToDate_pw & "# )"
>>
>> I'd rather not manually read through the table as it has 4,000 records
>> and is growing.
>>
>> Any ideas?
>>
>> -pw
>>
>> use paulwilliamson at spamcop dot net for e-mail
>
>The 'Not In (Select... syntax is known to be slow for larger tables.
>If you use the wizard to create an unmatched query it will show you an
>alternate syntax for returning the same records using a LEFT JOIN that
>runs much faster.
>
>James A. Fortune
Hi James.

I did as you suggested and converted this (from the wizard SQL
Syntax):

SELECT tblHistoryPersonIDs.PersonID
FROM tblHistoryPersonIDs LEFT JOIN tblDonations ON
tblHistoryPersonIDs.PersonID = tblDonations.PersonID
WHERE (((tblDonations.PersonID) Is Null));

To:

DoCmd.RunSQL "Delete * From tblHistoryPersonIDs LEFT JOIN
tblDonations ON tblHistoryPersonIDs.PersonID = tblDonations.PersonID
WHERE tblDonations.[DonationDate] Not Between #" & dFromDate_pw & "#
And #" & dToDate_pw & "#"

And I am getting "Specify the table containing the records you want to
delete". Can't figure it out. Am getting sleepy ;-0

Any ideas?

-pw

use paulwilliamson at spamcop dot net for e-mail


I didn't check your unmatched query, but when you get the unmatched
records the 'Not In (SELECT...' switches to 'IN (SELECT
tblHistoryPersonIDs.PersonID ...

That is, the unmatched query should return the ones that are 'Not In'
so they are now 'In.'


That hurts! <g>
I explained this in:

http://groups.google.com/group/comp....63454c21472dc3

but I didn't do that great a job of explaining it there either. If
that doesn't help, post back and I'll organize my thoughts into
something a little more elegant and understandable.
Okay. Go ahead ;-)
BTW, the ecommerce
code in that thread was from about six years ago and I cringed when I
saw it.

Then I'll have to check it out for sure! :)

Thanks again,

-paul
James A. Fortune

-pw

use paulwilliamson at spamcop dot net for e-mail
Nov 17 '05 #5
>
but I didn't do that great a job of explaining it there either. If
that doesn't help, post back and I'll organize my thoughts into
something a little more elegant and understandable.


Oops. I had a brain lapse and started a new thread instead of
replying to you. Oh well. Will be interesting to see if I get any
bites.

Thanks James,

-paul
-pw

use paulwilliamson at spamcop dot net for e-mail
Nov 17 '05 #6
On 17 Nov 2005 00:02:35 -0800, ji********@compumarc.com wrote:
pa******************@removespamcop.net wrote:
On 16 Nov 2005 15:20:27 -0800, ji********@compumarc.com wrote:
>pa******************@removespamcop.net wrote:
>> Hi,
>>
>> Using Access 2003.
>>
>> I am trying to delete records from one table/query
>> ("qryHistoryPersonIDs") if they don't exist in another table
>> ("qryDonations"). But the SQL syntax I came up with is taking forever
>> or locking up Access 2003.
>>
>> What am I doing wrong?
>>
>> The code is below. dFromDate_pw and dToDate_pw are set to values of
>> date fields on a form. qryHistoryPersonIDs contains one key field:
>>
>> DoCmd.RunSQL "Delete * From qryHistoryPersonIDs Where
>> qryHistoryPersonIDs.personID Not In (Select qryDonations.personid From
>> qryDonations Where tblDonations.[DonationDate] Not Between #" &
>> dFromDate_pw & "# And #" & dToDate_pw & "# )"
>>
>> I'd rather not manually read through the table as it has 4,000 records
>> and is growing.
>>
>> Any ideas?
>>
>> -pw
>>
>> use paulwilliamson at spamcop dot net for e-mail
>
>The 'Not In (Select... syntax is known to be slow for larger tables.
>If you use the wizard to create an unmatched query it will show you an
>alternate syntax for returning the same records using a LEFT JOIN that
>runs much faster.
>
>James A. Fortune


Hi James.

I did as you suggested and converted this (from the wizard SQL
Syntax):

SELECT tblHistoryPersonIDs.PersonID
FROM tblHistoryPersonIDs LEFT JOIN tblDonations ON
tblHistoryPersonIDs.PersonID = tblDonations.PersonID
WHERE (((tblDonations.PersonID) Is Null));

To:

DoCmd.RunSQL "Delete * From tblHistoryPersonIDs LEFT JOIN
tblDonations ON tblHistoryPersonIDs.PersonID = tblDonations.PersonID
WHERE tblDonations.[DonationDate] Not Between #" & dFromDate_pw & "#
And #" & dToDate_pw & "#"

And I am getting "Specify the table containing the records you want to
delete". Can't figure it out. Am getting sleepy ;-0

Any ideas?

-pw

use paulwilliamson at spamcop dot net for e-mail


I didn't check your unmatched query, but when you get the unmatched
records the 'Not In (SELECT...' switches to 'IN (SELECT
tblHistoryPersonIDs.PersonID ...

That is, the unmatched query should return the ones that are 'Not In'
so they are now 'In.'

I explained this in:

http://groups.google.com/group/comp....63454c21472dc3

but I didn't do that great a job of explaining it there either. If
that doesn't help, post back and I'll organize my thoughts into
something a little more elegant and understandable. BTW, the ecommerce
code in that thread was from about six years ago and I cringed when I
saw it.

James A. Fortune


I got it James:
strSQL_pw = _
"DELETE * From tblHistoryPersonIDs " & _
"WHERE NOT EXISTS " & _
"(SELECT * " & _
"FROM tblDonations " & _
"WHERE tblDonations.PersonID =
tblHistoryPersonIDs.PersonID " & _
"AND (DonationDate < #" & dFromDate_pw & "# " & _
"OR DonationDate > #" & dToDate_pw & "#))"

DoCmd.RunSQL strSQL_pw

And it ran quickly when I put in a date range to delete all the
records.

Phew! That was an important stumbling block because I have to do it
for a bunch of other combinations on this form.

Thanks!

-paul
-pw

use paulwilliamson at spamcop dot net for e-mail
Nov 17 '05 #7
pa******************@removespamcop.net wrote:
On 17 Nov 2005 00:02:35 -0800, ji********@compumarc.com wrote: I got it James:
strSQL_pw = _
"DELETE * From tblHistoryPersonIDs " & _
"WHERE NOT EXISTS " & _
"(SELECT * " & _
"FROM tblDonations " & _
"WHERE tblDonations.PersonID =
tblHistoryPersonIDs.PersonID " & _
"AND (DonationDate < #" & dFromDate_pw & "# " & _
"OR DonationDate > #" & dToDate_pw & "#))"

DoCmd.RunSQL strSQL_pw

And it ran quickly when I put in a date range to delete all the
records.

Phew! That was an important stumbling block because I have to do it
for a bunch of other combinations on this form.

Thanks!

-paul
-pw

use paulwilliamson at spamcop dot net for e-mail


I was dubious about the 'Not Between' also. I'm glad you found a way
to do it efficiently. The way I suggested should also have worked
quite well though.

James A. Fortune

Nov 17 '05 #8
On 17 Nov 2005 14:16:59 -0800, ji********@compumarc.com wrote:
pa******************@removespamcop.net wrote:
On 17 Nov 2005 00:02:35 -0800, ji********@compumarc.com wrote:

I got it James:
strSQL_pw = _
"DELETE * From tblHistoryPersonIDs " & _
"WHERE NOT EXISTS " & _
"(SELECT * " & _
"FROM tblDonations " & _
"WHERE tblDonations.PersonID =
tblHistoryPersonIDs.PersonID " & _
"AND (DonationDate < #" & dFromDate_pw & "# " & _
"OR DonationDate > #" & dToDate_pw & "#))"

DoCmd.RunSQL strSQL_pw

And it ran quickly when I put in a date range to delete all the
records.

Phew! That was an important stumbling block because I have to do it
for a bunch of other combinations on this form.

Thanks!

-paul
-pw

use paulwilliamson at spamcop dot net for e-mail


I was dubious about the 'Not Between' also. I'm glad you found a way
to do it efficiently. The way I suggested should also have worked
quite well though.

James A. Fortune


Yeah, that Not Between was a killer. Thank you much for your help!

-pw

use paulwilliamson at spamcop dot net for e-mail
Nov 18 '05 #9

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

Similar topics

3
by: Noddy | last post by:
We have an application that updates a row in a table. Sometimes Oracle does not respond for over 10 seconds. This is after an insert. It seems that there is a lock somewhere. This is a multi user...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
2
by: Maurice KRAIT | last post by:
Hello all, I use ACCESS 97. I want to delete all records of a table "TABLE RESULT" , the name of which includes spaces. It seems to me that the correct syntax is as follows : DoCmd.RunSQL ...
6
by: David | last post by:
I am trying to insert an employee number into the EmpNbr field in my main table from a form where I add a new employee to my employee table. I was hoping this command would work, but it isn't. ...
0
by: John Bailo | last post by:
Has anyone downloaded the DirectX SDK...it's taking me forever! I want to do some GDI programming in c# using VC#Express
7
by: travlintom | last post by:
Hi. I'm new to VB.net and am used to working with recordsets (much easier). I have a datagrid that, when the user double clicks on a row, I am giving them a chance to delete it. I thought this...
5
by: Sam777 | last post by:
I was under the impression that creating the app_offline.htm file at the root of the webapp would cause all handles to be closed so that the app could be removed. Unfortunately, this isn't the...
2
by: jujube | last post by:
Hi, I thought I found a great command in RunSQL, but.... In my Unload event for a form, I added some clean-up code: Private Sub Form_Unload(Cancel As Integer) If Not IsNull(Me.ID.Value) And...
3
by: jl2886 | last post by:
I would like a all records from (a table) where .="Rejected" and input those records into the (a table). Both tables are exactly the same as far as structure. I have created a macro with one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.