Cita:
Iniciado por ejbsoft Hola
Qué tal algo tan simple como esto?
SELECT T0.[ItemCode], T0.[Dscription], sum(T0.[Quantity])
FROM INV1 T0 INNER JOIN OINV T1 ON T0.[DocEntry] = T1.[DocEntry]
WHERE T1.[DocDate] BETWEEN '01-01-2016' AND '31-01-2016'
GROUP BY T0.[ItemCode], T0.[Dscription]
ORDER BY T0.[ItemCode] ASC
unión all
SELECT T2.[ItemCode], T2.[Dscription], sum(T2.[Quantity])
FROM RIN1 T2 INNER JOIN ORIN T3 ON T2.[DocEntry] = T3.[DocEntry]
WHERE T2.[DocDate] BETWEEN '01-01-2016' AND '31-01-2016'
and t2.[itemcode] not in (select itemcode from inv1 WHERE DocDate BETWEEN '01-01-2016' AND '31-01-2016' )
GROUP BY T2.[ItemCode], T2.[Dscription]
ORDER BY T2.[ItemCode] ASC
Y la resta??? esta preguntando por como hacer la resta de las ventas menos las compras
Código SQL:
Ver originalSELECT ventas.itemcode,ventas.dscription, ventas-devoluciones AS resta FROM(
SELECT T0.[ItemCode], T0.[Dscription], SUM(T0.[Quantity]) AS ventas
FROM INV1 T0 INNER JOIN OINV T1 ON T0.[DocEntry] = T1.[DocEntry]
WHERE T1.[DocDate] BETWEEN '01-01-2016' AND '31-01-2016'
GROUP BY T0.[ItemCode], T0.[Dscription] ) AS ventas
LEFT JOIN
(
SELECT T2.[ItemCode], T2.[Dscription], SUM(T2.[Quantity]) AS devoluciones
FROM RIN1 T2 INNER JOIN ORIN T3 ON T2.[DocEntry] = T3.[DocEntry]
WHERE T2.[DocDate] BETWEEN '01-01-2016' AND '31-01-2016'
GROUP BY T2.[ItemCode], T2.[Dscription]
) AS devoluciones ON (ventas.itemcode=devoluciones.itemcode)