on 04-20-2010 9:31 PM
Tengo un problema, aqui mi poco conocimiento o mas bien práctica con sql, tengo un query que me saca todas las líneas de las facturas para ventas por productos, necesito uno donde pueda sumarla por producto y por serie, hacer un tipo de distinc y un sum. ¿alguien me podría ayudar?.
esto es lo que tengo
SELECT T0.[ItemCode], T0.[Quantity], T0.[LineTotal], T0.[DocDate], T1.[Series] FROM INV1 T0 INNER JOIN OINV T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OITM T2 ON T0.ItemCode = T2.ItemCode INNER JOIN ITM1 T3 ON T2.ItemCode = T3.ItemCode INNER JOIN NNM1 T4 ON T1.Series = T4.Series WHERE T4.[Seriesname] =[%0] and T1.[DocDate] >=[%1] and t1.docdate<=[%2]
sip gracias.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hola...
Si quieres la suma de los totales por producto no hay problema, en cuanto a la serie, se supone que ya estas filtrando el reporte por serie.
El tema es que te arrojará tantas lineas como fechas de contabilización distintas tengas, por lo que he modificado basicamente eso, y además le agregué el distinct y el sum (utilizando un alias distinto en la tabla de
modo de poder aplicar un filtro dentro de la subconsulta)
SELECT DISTINCT T0.[ItemCode], T0.[Quantity], (SELECT SUM(X.LineTotal)
FROM INV1 X INNER JOIN OINV Y ON X.DocEntry = Y.DocEntry
WHERE X.ItemCode = T0.ItemCode
AND Y.DocDate = T1.DocDate), T0.[DocDate], T1.[Series] FROM INV1 T0 INNER JOIN OINV T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OITM T2 ON T0.ItemCode = T2.ItemCode INNER JOIN ITM1 T3 ON T2.ItemCode = T3.ItemCode
INNER JOIN NNM1 T4 ON T1.Series = T4.Series WHERE T4.[Seriesname] = [%0] --and T1.[DocDate] >=[%1] and t1.docdate<=[%2]
GROUP BY T0.[ItemCode], T0.[Quantity], T0.[DocDate], T1.[Series], T1.[DocDate]
Pruebalo y me comentas,
Espero te sea de ayuda,
Saludos Cordiales,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
96 | |
10 | |
9 | |
6 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.