05/08/2011, 09:08
|
| Colaborador | | Fecha de Ingreso: agosto-2006 Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 18 años, 3 meses Puntos: 774 | |
Respuesta: Agrupar y sumar que quede en una linea Sorry error mio :P SELECT T1.[SlpName], T1.U_BKS_ZONA, SUM(T2.U_BKS_CAMI) AS 'Cantidad de Formas', SUM(T2.[LineTotal]) AS [Cotizados]
FROM(SELECT DISTINCT T1.[SlpName], T1.U_BKS_ZONA, SUM(T2.U_BKS_CAMI) AS 'Cantidad de Formas', SUM(T2.[LineTotal]) AS [Cotizados],
CASE WHEN U_Status = 'A' THEN (SUM(T2.[LineTotal])) ELSE 0 END AS 'Aprobados',
CASE WHEN U_Status = 'N' THEN (SUM(T2.[LineTotal])) ELSE 0 END AS 'Anulados',
CASE WHEN U_Status = 'P' THEN (SUM(T2.[LineTotal])) ELSE 0 END AS 'Perdidos',
CASE WHEN U_Status = 'O' THEN (SUM(T2.[LineTotal])) * -1 ELSE 0 END AS 'Otros Periodos'
FROM OQUT T0 INNER JOIN
OSLP T1 ON T0.SlpCode = T1.SlpCode INNER JOIN
QUT1 T2 ON T0.DocEntry = T2.DocEntry
WHERE (T0.DocDate BETWEEN '2011-01-01' AND '2011-08-03')
GROUP BY T1.[SlpName], T1.U_BKS_ZONA
)
FROM OSLP T1
GROUP BY T1.[SlpName], T1.U_BKS_ZONA
Prueba quitando el order by si no no te va a dejar probar la funcion :)
Saludos!
__________________ What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me |