
The way I am trying to accomplish this is through a query which does the following:
([Vendors] LEFT JOIN [select statement which captures the sum of amount spent and amount closed in FY12])
LEFT JOIN
[select statement which captures the sum of the amount spent and closed in previous fiscal years]
That way, I will have all the relevant fields which I can then sum, subtract from budget, etc straight on the report.
What I am having a lot of trouble with is the formatting of the nested left joins. I feel like I am very close to what I want, but there is a bracket in there somewhere that I am missing (getting a join statement syntax error). The following is my sql statement. Can anyone help me edit my syntax? Thank you!!!
PHP:
SELECT Vendors.VendorName,
Vendors.Current_FY_Budget,
SumofPOAmountActual1, SumofClosed,
NonContractVendors.MultYearContract,
SumofAmountActualPrev, SumofClosedPrev
FROM
[(Vendors as Vend)
LEFT JOIN
(SELECT V.VendorName, Sum(IIf(P.BHSRequisitionNum Like '2012*',P.POAmountActual,Null)) AS SpentFY12, Sum(IIf(P.BHSRequisitionNum Like '2012*',ClosedAmount,Null)) AS ClosedFY12
FROM Vendors AS V LEFT JOIN PurchaseOrders AS P ON V.VendorName = P.VendorName
GROUP BY V.VendorName as CurrentVend) on Vend.VendorName= CurrentVend.VendorName as FirstJoin]
LEFT JOIN
(SELECT V.VendorName, Sum(IIf(P.BHSRequisitionNum Not Like '2012*',P.POAmountActual,Null)) AS Spent_previous, Sum(IIf(P.BHsRequisitionNum Not Like '2012*',P.ClosedAmount,Null)) AS Closed_previous
FROM Vendors AS V LEFT JOIN PurchaseOrders AS P ON V.VendorName=P.VendorName
GROUP BY V.VendorName as PrevVend)
on FirstJoin.VendorName= PrevVend.VendorName
Group by Vendors.VendorName, Vendors.Current_FY_Budget;