Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Query Help Please

I have this query and would like to add a variable:

I would like to limit the sales numbers only for a specific supplier from OMRC

I have tried a number of time with out success.

Any help would be greatly appreciated.

Regards

Here's the query;

SELECT distinct T0.CardCode, T0.CardName, T2.SlpName,

(SELECT SUM(DocTotal - TotalExpns - VatSum) FROM OINV WHERE CardCode = T0.CardCode

AND YEAR(DocDate) = '2007') AS [Sales 2007],

(SELECT SUM(DocTotal - TotalExpns - VatSum) FROM OINV WHERE CardCode = T0.CardCode

AND YEAR(DocDate) = '2008') AS [Sales 2008],

(SELECT SUM(DocTotal - TotalExpns - VatSum) FROM OINV WHERE CardCode = T0.CardCode

AND YEAR(DocDate) = '2009') AS [Sales 2009]

FROM [dbo].[OCRD] T0 LEFT JOIN [dbo].[OINV] T1 ON T1.CardCode = T0.CardCode INNER JOIN OSLP T2 ON T0.SlpCode = T2.SlpCode

Where T0.CardCode not like 'V%'

GROUP BY T0.CardCode, T0.CardName, T2.SlpName

UNION

SELECT Distinct T0.CardCode, T0.CardName, T2.SlpName,

(SELECT SUM(DocTotal - TotalExpns - VatSum) * -1 FROM ORIN WHERE CardCode = T0.CardCode

AND YEAR(DocDate) = '2007') AS [Sales 2007],

(SELECT SUM(DocTotal - TotalExpns - VatSum) * -1 FROM ORIN WHERE CardCode = T0.CardCode

AND YEAR(DocDate) = '2008') AS [Sales 2008],

(SELECT SUM(DocTotal - TotalExpns - VatSum) * -1 FROM ORIN WHERE CardCode = T0.CardCode

AND YEAR(DocDate) = '2009') AS [Sales 2009]

FROM [dbo].[OCRD] T0 LEFT JOIN [dbo].[ORIN] T1 ON T1.CardCode = T0.CardCode INNER JOIN OSLP T2 ON T0.SlpCode = T2.SlpCode

Where T0.CardCode not like 'V%'

GROUP BY T0.CardCode, T0.CardName, T2.SlpName

Former Member
Not what you were looking for? View more on this topic or Ask a question