Skip to Content
0
Jan 11, 2011 at 10:05 AM

Sql Query

16 Views

Hi,

I make this query:

SELECT 'Facturas', T0.[CardCode], T0.[CardName], T1.[SlpName], SUM(Quantity) as Unidades, SUM(LineTotal) as Euros

FROM OCRD T0 INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN OINV T2 ON T0.CardCode = T2.CardCode INNER JOIN INV1 T3 ON T2.DocEntry = T3.DocEntry WHERE T1.[SlpName] >=[%0] AND T1.[SlpName] <=[%1] AND T2.[DocDueDate] >=[%2] AND T2.[DocDueDate] <=[%3]

GROUP BY T0.[CardCode], T0.[CardName], T1.[SlpName]

UNION

SELECT 'Abonos', T0.[CardCode], T0.[CardName], T1.[SlpName], SUM(Quantity *-1) as Unidades, SUM(LineTotal *-1) as Euros

FROM OCRD T0 INNER JOIN OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN ORIN T2 ON T0.CardCode = T2.CardCode INNER JOIN RIN1 T3 ON T2.DocEntry = T3.DocEntry WHERE T1.[SlpName] >=[%0] AND T1.[SlpName] <=[%1] AND T2.[DocDueDate] >=[%2] AND T2.[DocDueDate] <=[%3]

GROUP BY T0.[CardCode], T0.[CardName], T1.[SlpName]

But now I want to modify this one to obtain items sold by customer grouped choosing the date that I want, ex: from 01/01/2010 to 31/12/2010

Thanks.

Antonio.