Ver Mensaje Individual
  #10 (permalink)  
Antiguo 05/08/2011, 09:46
Josmery
 
Fecha de Ingreso: agosto-2008
Mensajes: 17
Antigüedad: 16 años, 4 meses
Puntos: 0
Respuesta: Agrupar y sumar que quede en una linea

Cita:
Iniciado por Libras Ver Mensaje
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!