GK in the UK
Registered User.
- Local time
- Today, 20:56
- Joined
- Dec 20, 2017
- Messages
- 281
Help please on sub query syntax. I've been tweaking this for ages, read the Allen Browne stuff etc. etc. but still can't get it right.
I am trying to insert the sub query into the FROM clause. I need the summed value qValueAllocated. The main query is also a group sum of n records from a different table.
Here's the main query:
Here is the sub query that I want to insert in the FROM clause. It's tested and working gets the summed value I need per the criteria.
I would replace "PIN000103" with tblTransHeaders.thDocReference (from the main query)
I am trying to insert the sub query into the FROM clause. I need the summed value qValueAllocated. The main query is also a group sum of n records from a different table.
Here's the main query:
Code:
SELECT tblCustsSupps.CustSuppID, tblTransHeaders.TransHeaderID, tblTransHeaders.thDocReference, tblTransHeaders.thDate, tblTransHeaders.thDueDate, tblTransHeaders.thYourRef, tblTransHeaders.thPpDiscount, tblTransHeaders.thPpdAutoAdjust, tblTransHeaders.thPpdTaken, Sum(Nz([tblTransLines].[tlNetValue],0)+Nz([tblTransLines].[tlVatValue],0)) AS qGrossValue
FROM tblCustsSupps INNER JOIN
(tblTransHeaders INNER JOIN tblTransLines ON tblTransHeaders.TransHeaderID = tblTransLines.tlTransHeaderFK)
ON tblCustsSupps.CustSuppID = tblTransHeaders.thCustSuppFk
GROUP BY tblCustsSupps.CustSuppID, tblTransHeaders.TransHeaderID, tblTransHeaders.thDocReference, tblTransHeaders.thDate, tblTransHeaders.thDueDate, tblTransHeaders.thYourRef, tblTransHeaders.thPpDiscount, tblTransHeaders.thPpdAutoAdjust, tblTransHeaders.thPpdTaken
HAVING (((tblCustsSupps.CustSuppID)=900))
ORDER BY tblTransHeaders.TransHeaderID;
Here is the sub query that I want to insert in the FROM clause. It's tested and working gets the summed value I need per the criteria.
I would replace "PIN000103" with tblTransHeaders.thDocReference (from the main query)
Code:
SELECT tblAllocations.allocTransHeaderFK, tblAllocations.allocDocReference, tblAllocations.allocDate, Sum(tblAllocations.allocValueAllocated) AS qValueAllocated
FROM tblAllocations
GROUP BY tblAllocations.allocTransHeaderFK, tblAllocations.allocDocReference, tblAllocations.allocDate
HAVING (((tblAllocations.allocDocReference)="PIN000103"));