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

Este es el error que da quitandole el order by

Msg 156, Level 15, State 1, Line 13
Incorrect syntax near the keyword 'FROM'.

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

Gracias por estar pendiente de mi caso.