subquery - not enough memory (1 Viewer)

illusionek

Registered User.
Local time
Yesterday, 18:36
Joined
Dec 31, 2013
Messages
92
Hello

I got this query with a subquery and it takes couple seconds to run.

However if I try to go to the last record, export it to Excel via ExternalData tab or Make Table, my Access stops working and then I get an error message there is not enough memory.

I am getting lost here as in the end I need to link Excel to this query.

Any idea why it happens?




Code:
SELECT qryCalculations.[Item Number], qryCalculations.[Week Commencing], qryCalculations.ClosingInventory, (Select qry2.ClosingInventory from qryCalculations as qry2 where qry2.[Item Number] = qryCalculations.[Item Number] and qry2.[Week Commencing] = qryCalculations.[Week Commencing] - 7) AS PreviousClosingInventory
FROM qryCalculations;
 

Minty

AWF VIP
Local time
Today, 02:36
Joined
Jul 26, 2013
Messages
10,371
Approximately how many records are involved / should be returned?
 

illusionek

Registered User.
Local time
Yesterday, 18:36
Joined
Dec 31, 2013
Messages
92
I cannot check how many records are actually returned by this query but I would expect 7k-10k.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:36
Joined
May 7, 2009
Messages
19,245
how about using a join:

SELECT qryCalculations.[Item Number], qryCalculations.[Week Commencing], qryCalculations.ClosingInventory, qry2.ClosingInventory As PreviousClosingInventory
FROM qryCalculations LEFT JOIN qryCalculations AS qry2 ON qryCalculations.[Item Number] = qry2.[Item Number]
WHERE qry2.[Week Commencing] = qryCalculations.[Week Commencing] - 7;
 

illusionek

Registered User.
Local time
Yesterday, 18:36
Joined
Dec 31, 2013
Messages
92
Unfortunately now it does not run at all with this join, I got error message about not enough memory.
 

Simon_MT

Registered User.
Local time
Today, 02:36
Joined
Feb 26, 2007
Messages
2,177
Write a separate query forcing Item Number into the Query with a Left Join and setting the ClosingInventory using NZ or is null = 0.

Simon
 

illusionek

Registered User.
Local time
Yesterday, 18:36
Joined
Dec 31, 2013
Messages
92
Hi guys

Many thanks for looking into this post. Unfortunately since then I discovered that I have a more fundamental issue with this subequery than just a performance. For some reason I cannot get it right :banghead:

I posted sample data in post #24 in the below thread if anyone would like to look at it and help me

http://www.access-programmers.co.uk/forums/showthread.php?t=286678&page=2
 

Users who are viewing this thread

Top Bottom