Buen día , tengo este código y quiero sacar la cantidad vendida por agente por mes. Pero revisando las cantidades con el reporte de análisis de ventas por artículos por mes me salen diferencias en algunos meses, no logro que me cuadre la cantidad. Alguien sabe si me falta algo a mi código ?
SELECT DISTINCT Max(T4.[CardCode]) as 'Cliente ', Max(T4.[CardName]) as 'Cliente', T1.[ItemCode] , Max(T1.[Dscription]) as 'Descripción', Max(T2.[SlpName]) as 'Agente',
(CASE WHEN MONTH (T0.[DocDate])= 1 THEN SUM (T1.[Quantity]) ELSE 0 END) 'ENERO',
(CASE WHEN MONTH (T0.[DocDate]) = 2 THEN SUM (T1.[Quantity]) ELSE 0 END) AS FEBRERO,
(CASE WHEN MONTH (T0.[DocDate]) = 3 THEN SUM (T1.[Quantity]) ELSE 0 END) AS MARZO,
(CASE WHEN MONTH (T0.[DocDate]) = 4 THEN SUM (T1.[Quantity]) ELSE 0 END) AS ABRIL,
(CASE WHEN MONTH (T0.[DocDate]) = 5 THEN SUM (T1.[Quantity]) ELSE 0 END) AS MAYO,
(CASE WHEN MONTH (T0.[DocDate]) = 6 THEN SUM (T1.[Quantity]) ELSE 0 END) AS JUNIO,
(CASE WHEN MONTH (T0.[DocDate]) = 7 THEN SUM (T1.[Quantity]) ELSE 0 END) AS JULIO,
(CASE WHEN MONTH (T0.[DocDate]) = 8 THEN SUM (T1.[Quantity]) ELSE 0 END) AS AGOSTO,
(CASE WHEN MONTH (T0.[DocDate]) = 9 THEN SUM (T1.[Quantity]) ELSE 0 END) AS SEPTIEMBRE,
(CASE WHEN MONTH (T0.[DocDate]) = 10 THEN SUM (T1.[Quantity]) ELSE 0 END) AS OCTUBRE,
(CASE WHEN MONTH (T0.[DocDate]) = 11 THEN SUM (T1.[Quantity]) ELSE 0 END) AS NOVIEMBRE,
(CASE WHEN MONTH (T0.[DocDate]) = 12 THEN SUM (T1.[Quantity]) ELSE 0 END) AS DICIEMBRE
FROM OINV T0
INNER JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry]
INNER JOIN OSLP T2 ON T0.[SlpCode] = T2.[SlpCode]
INNER JOIN NNM1 T3 ON T0.[Series] = T3.[Series]
INNER JOIN OCRD T4 ON T0.[CardCode] = T4.[CardCode]
WHERE (T3.[SeriesName] BETWEEN [%0] AND [%1]) AND (T0.[DocDate] BETWEEN [%2] AND [%3])
group by T1.[ItemCode] , T0.[DocDate]