blindeddestiny
Technical User
Hi Guys,
Wondering if anyone can help me with some deciphering of code.
In short I am working with Access and trying to run a report that ends up using 100% of the cpu and eventually having to force quit the application. I have found the source of the problem and code below, but having trouble figuring out exactly why it is doing what it's doing.
I have posted the code and all the queries it needs to run. Al other queries run and complete quickly it's the last one that causes problems.
Thanks in advance for any help.
QryArrears
-----------
SELECT q.paymentid, q.tenancyid, u.unitref, q.arrears
FROM tenancy AS t, unit AS u, (select paymentid, a.tenancyid, arrears
from qrypaymentstatementcumarrears a,
(
select tenancyid, max(date) as maxdate
from qrypaymentstatementcumarrears
where Date <=Forms![frmArrearsReport]![txtDate]
group by tenancyid
) b
where a.tenancyid = b.tenancyid and a.date = b.maxdate) AS q
WHERE q.tenancyid = t.tenancyid
and t.unitid = u.unitid
and arrears > 0
ORDER BY unitref;
'This is referncing a query that references equations in several 'other queries. However these all run successfully. Below is the 'SQL for the other queries:
qryPaymentStatementCumArrears
---------------------------------
SELECT OutPay.paymentid, OutPay.tenancyid, OutPay.date, OutPay.due, OutPay.received, (select sum(Arrears)
from qryPaymentStatementArrears as inPay
where inPay.date <= outPay.date and inPay.tenancyid=outpay.tenancyid) AS Arrears, OutPay.note, OutPay.chequename, OutPay.Rent
FROM qryPaymentStatementArrears AS OutPay
GROUP BY OutPay.paymentid, OutPay.tenancyid, OutPay.date, OutPay.due, OutPay.received, OutPay.note, OutPay.chequename, OutPay.Rent, OutPay.Arrears
ORDER BY OutPay.tenancyid, OutPay.date;
qryPaymentStatementArrears
----------------------------
SELECT qryPaymentStatement.paymentid, qryPaymentStatement.tenancyid, qryPaymentStatement.Date, qryPaymentStatement.Due, qryPaymentStatement.Received, due-received AS Arrears, qryPaymentStatement.Note, qryPaymentStatement.ChequeName, IIf(IsRent=0,"No","Yes") AS Rent
FROM qryPaymentStatement;
QryPaymentStatement
----------------------
select paymentid, tenancyid, Date,amount as [Due], 0 as [Received], Note, ChequeName, IsRent
from payment
where type = "Due"
UNION select paymentid, tenancyid, date,0,amount, note, ChequeName, IsRent
from payment
where type = "Received"
ORDER BY date;
The final query above simply references a table.
Wondering if anyone can help me with some deciphering of code.
In short I am working with Access and trying to run a report that ends up using 100% of the cpu and eventually having to force quit the application. I have found the source of the problem and code below, but having trouble figuring out exactly why it is doing what it's doing.
I have posted the code and all the queries it needs to run. Al other queries run and complete quickly it's the last one that causes problems.
Thanks in advance for any help.
QryArrears
-----------
SELECT q.paymentid, q.tenancyid, u.unitref, q.arrears
FROM tenancy AS t, unit AS u, (select paymentid, a.tenancyid, arrears
from qrypaymentstatementcumarrears a,
(
select tenancyid, max(date) as maxdate
from qrypaymentstatementcumarrears
where Date <=Forms![frmArrearsReport]![txtDate]
group by tenancyid
) b
where a.tenancyid = b.tenancyid and a.date = b.maxdate) AS q
WHERE q.tenancyid = t.tenancyid
and t.unitid = u.unitid
and arrears > 0
ORDER BY unitref;
'This is referncing a query that references equations in several 'other queries. However these all run successfully. Below is the 'SQL for the other queries:
qryPaymentStatementCumArrears
---------------------------------
SELECT OutPay.paymentid, OutPay.tenancyid, OutPay.date, OutPay.due, OutPay.received, (select sum(Arrears)
from qryPaymentStatementArrears as inPay
where inPay.date <= outPay.date and inPay.tenancyid=outpay.tenancyid) AS Arrears, OutPay.note, OutPay.chequename, OutPay.Rent
FROM qryPaymentStatementArrears AS OutPay
GROUP BY OutPay.paymentid, OutPay.tenancyid, OutPay.date, OutPay.due, OutPay.received, OutPay.note, OutPay.chequename, OutPay.Rent, OutPay.Arrears
ORDER BY OutPay.tenancyid, OutPay.date;
qryPaymentStatementArrears
----------------------------
SELECT qryPaymentStatement.paymentid, qryPaymentStatement.tenancyid, qryPaymentStatement.Date, qryPaymentStatement.Due, qryPaymentStatement.Received, due-received AS Arrears, qryPaymentStatement.Note, qryPaymentStatement.ChequeName, IIf(IsRent=0,"No","Yes") AS Rent
FROM qryPaymentStatement;
QryPaymentStatement
----------------------
select paymentid, tenancyid, Date,amount as [Due], 0 as [Received], Note, ChequeName, IsRent
from payment
where type = "Due"
UNION select paymentid, tenancyid, date,0,amount, note, ChequeName, IsRent
from payment
where type = "Received"
ORDER BY date;
The final query above simply references a table.