Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3523

Help with a query!

$
0
0

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$
July45000
August55000
September60000
October80000
November90000
December45000
January35000
February110000
March90000
April50000
May40000
June20000

 

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


Viewing all articles
Browse latest Browse all 3523

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>