P
PeteCresswell
Got a query that I'm trying to return the last two of something with,
but for some entities it is returning two rows.
I concocted a sample application that reproduces the problem.
The app can be DL'd from www.wchs59.com/Playpen.zip.
The query in question is named: "qryBadBoy".
You will need to View | SQL to really see what's going on
For what it's worth, here's the SQL:
--------------------------------------------------------------------------------
SELECT P1.TrancheID, P1.PaymentAmount AS [PaymentAmount#1],
P2.PaymentAmount AS [PaymentAmount#2], ([P1].[PaymentAmount]+[P2].
[PaymentAmount])/2 AS PaymentAmountAverageLast2
FROM qryTrancheFund_Last2Payments_Common AS P1,
qryTrancheFund_Last2Payments_Common AS P2
WHERE (((P1.PaymentDate)=(SELECT MAX(PaymentDate)
FROM tblPayment AS P3
WHERE P3.TrancheID = P1.TrancheID)) AND ((P2.PaymentDate)=(SELECT
MAX(PaymentDate)
FROM tblPayment AS P4
WHERE P4.TrancheID = P1.TrancheID
AND P4.PaymentDate <
(SELECT MAX(PaymentDate)
FROM tblPayment AS P5
WHERE P5.TrancheID = P1.TrancheID))));
--------------------------------------------------------------------------------
I'm way, *way*, WAY over my head with this one - mainly doing a rote
imitation of something similar.
Can anybody shed some light?
but for some entities it is returning two rows.
I concocted a sample application that reproduces the problem.
The app can be DL'd from www.wchs59.com/Playpen.zip.
The query in question is named: "qryBadBoy".
You will need to View | SQL to really see what's going on
For what it's worth, here's the SQL:
--------------------------------------------------------------------------------
SELECT P1.TrancheID, P1.PaymentAmount AS [PaymentAmount#1],
P2.PaymentAmount AS [PaymentAmount#2], ([P1].[PaymentAmount]+[P2].
[PaymentAmount])/2 AS PaymentAmountAverageLast2
FROM qryTrancheFund_Last2Payments_Common AS P1,
qryTrancheFund_Last2Payments_Common AS P2
WHERE (((P1.PaymentDate)=(SELECT MAX(PaymentDate)
FROM tblPayment AS P3
WHERE P3.TrancheID = P1.TrancheID)) AND ((P2.PaymentDate)=(SELECT
MAX(PaymentDate)
FROM tblPayment AS P4
WHERE P4.TrancheID = P1.TrancheID
AND P4.PaymentDate <
(SELECT MAX(PaymentDate)
FROM tblPayment AS P5
WHERE P5.TrancheID = P1.TrancheID))));
--------------------------------------------------------------------------------
I'm way, *way*, WAY over my head with this one - mainly doing a rote
imitation of something similar.
Can anybody shed some light?