I have 2 queries that return results pertaining to trade debtors. The first returns amounts per month for all trade debtors while the second returns amounts per month for all trade debtors after 30 days.
1st query
SELECT T2.Name AS Period,
SUM(T1.LineTotal) AS CurrentAmount,
MAX(T0.DocRate) AS ExchangeRate
FROM OINV T0 INNER JOIN
INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
dbo.OFPR AS t2 ON T1.FinncPriod = T2.AbsEntry
WHERE T0.DocStatus = 'O' AND t0.DocDate BETWEEN '2007-01-01' AND '2007-12-01'
GROUP BY T2.Name
2nd query
SELECT T2.Name AS Period,
SUM(T1.LineTotal) AS NonCurrentAmount,
MAX(T0.DocRate) AS ExchangeRate
FROM OINV T0 INNER JOIN
INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
dbo.OFPR AS t2 ON T1.FinncPriod = T2.AbsEntry
WHERE T0.DocStatus = 'O' AND DATEDIFF(day,t0.DocDate,t0.DocDueDate)>30
AND t0.DocDate BETWEEN '2007-01-01' AND '2007-12-01'
GROUP BY T2.Name
How do I combine the 2 queries above into one such that the resulting query will return results in 4 columns; Period, CurrentAmount, NonCurrentAmount and exchange rate.
You could move the difference in
whereclause to acasestatement: