The following code works in Sage200.
SELECT bcs.BomReference
,bcs.DateTimeCosted
,bcs.TotalCost
FROM (
SELECT BomReference
,Max(DateTimeCosted) AS MaxDate
FROM NDM_Sage200.dbo.BomCostSession BomCostSession
GROUP BY BomReference
) AS ldc
INNER JOIN BomCostSession AS bcs ON bcs.BomReference = ldc.BomReference
AND bcs.DateTimeCosted = ldc.MaxDate
ORDER BY BomReference
As soon as I try extending this with an INNER JOIN to another table to get more columns (using BomReference), I get the error message:
Could not add the table (.
See below for example of modified code; I have to use 2 joins to get to the table I need, but have the same error whatever I join onto the working code.
SELECT bcs.BomReference, bcs.DateTimeCosted, bcs.TotalCost, BomBuildProduct.StockDescription
FROM (
SELECT BomReference,
Max(DateTimeCosted) AS MaxDate
FROM NDM_Sage200.dbo.BomCostSession BomCostSession
GROUP BY BomReference
) AS ldc
INNER JOIN
BomCostSession as bcs
ON bcs.BomReference = ldc.BomReference AND
bcs.DateTimeCosted = ldc.MaxDate
***** Fails when adding INNER JOIN here *****
INNER JOIN
BomBuildPackage
ON BomCostSession.BomBuildPackageID = BomBuildPackage.BomBuildPackageID
INNER JOIN
BomBuildProduct
ON BomBuildPackage.BomRecordID = BomBuildProduct.BomRecordID
ORDER BY BomReference
What am I doing wrong ? I need to expand the query with data from several tables.
I also think that when using MSQuery on the section that works, it offers no options to add any tables - this makes it rather difficult to try options.
Why ?