Hi,
I need to put together a query - which if you select a salesperson from OSLP table and a year, so let's say
Salesperson = Richard
Year = 2016
It should return the sales persons invoiced total per month (ex tax) - minus the credits applied in those particular months:
Month | $ |
---|---|
July | 45000 |
August | 55000 |
September | 60000 |
October | 80000 |
November | 90000 |
December | 45000 |
January | 35000 |
February | 110000 |
March | 90000 |
April | 50000 |
May | 40000 |
June | 20000 |
At the moment - I have the following to
SELECT sum(Case T0.[DocCur] When 'AUD' then T0.[DocTotal]-T0.[VatSum]-T0.[TotalExpns] else T0.[DocTotalFC]-T0.[VatSumFC] end) as 'Sale Amount'
FROM OINV T0
INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode
INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode
INNER JOIN OCRG T3 ON T2.GroupCode = T3.GroupCode
WHERE T1.[SlpName] = [%0] and T0.[DocDate] >= [%1] and T0.[DocDate] <= [%2]
UNION ALL
SELECT sum(Case T0.[DocCur] When 'AUD' then (T0.[DocTotal]-T0.[VatSum]-T0.[TotalExpns])*-1 else (T0.[DocTotalFC]-T0.[VatSumFC]- T0.[TotalExpFC])*-1 end) as 'Sale Amount'
FROM ORIN T0
INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode
INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode
INNER JOIN OCRG T3 ON T2.GroupCode = T3.GroupCode
WHERE T1.[SlpName] = [%0] and T0.[DocDate] >= [%1] and T0.[DocDate] <= [%2]
But - this results in two figures being presented - one for the invoices and the other for credits.
How do I go about combining these to one figure?
Further to this - I have no idea how to achieve my list of months in one column with the invoices in the other.
The reason that I need it to display July through June is that in Australia this is the financial year.
Any help with this would be appreciated.
Regards,
Rick