Declare @Fromdate as datetime
Declare @Todate as datetime
SET @FROMDATE = /*SELECT MIN(Docdate) FROM OINV T1 WHERE T1.DocDate >= */ '[%0]'
SET @TODATE = /*SELECT MAX(Docdate) FROM OINV T1 WHERE T1.DocDate <= */ '[%1]'
SET @FROMDATE = /*SELECT MIN(Docdate) FROM ORIN T1 WHERE T1.DocDate >= */ '[%0]'
SET @TODATE = /*SELECT MAX(Docdate) FROM ORIN T1 WHERE T1.DocDate <= */ '[%1]'
SELECT DISC AS 'Description', SUM(SALESV) as 'Sales', SUM(RETURNSV) as 'Returns', SUM(SALESV)-SUM(RETURNSV) as 'Net Sales'
FROM
(SELECT
'TOTAL SALES' [DISC], (sum(T1.[GTotal])-sum(T1.[VatSum])) [SalesV], 0 [ReturnsV], (sum(T1.[GTotal])-sum(T1.[VatSum])) [TSalesV], 0 [TReturnsV]
FROM
OINV T0
INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode
WHERE
T0.[DocDate] >=@FromDate AND T0.[DocDate] <=@ToDate
UNION ALL
SELECT
'TOTAL SALES' [DISC], 0[SalesV], (sum(T1.[GTotal])-sum(T1.[VatSum])) [ReturnsV], 0[TSalesV], (sum(T1.[GTotal])-sum(T1.[VatSum])) [TReturnsV]
FROM
ORIN T0
INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode
WHERE
T0.[DocDate] >=@FromDate AND T0.[DocDate] <=@ToDate)S
GROUP BY
DISC
Regards
Kennedy