subquery - not enough memory (1 Viewer)

illusionek

Registered User.
Local time
Today, 12:54
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, 20:54
Joined
Jul 26, 2013
Messages
10,371
Approximately how many records are involved / should be returned?
 

illusionek

Registered User.
Local time
Today, 12:54
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
Tomorrow, 03:54
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
Today, 12:54
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, 20:54
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
 

Users who are viewing this thread

Top Bottom