Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/04/2013, 07:42
Avatar de chris225
chris225
 
Fecha de Ingreso: octubre-2012
Ubicación: Medellin
Mensajes: 149
Antigüedad: 11 años, 6 meses
Puntos: 2
suma el resultados de todos los datos devueltos

buenas tengo esta consulta

select (TD.BRUTO - isnull((select SUM(CANTIDAD*VALORUNIT) from MVTRADE where TIPODCTONC in ('NC','NB','NU') and NUMFACTNC=TD.NRODCTO),0)) *
(SELECT (PorcReca/100)FROM GS_Recaudo where (DATEDIFF(day,'2010-01-06','2010-01-06') between Desde and Hasta))
* ((select (PorcReca/100) from GS_ConfEscal where Nombre=VE.NOMESCALAFON)) as total
from Trade as TD
inner join GS_Recaudo AS RC on RC.CodeVen = TD.CODVEN
inner join VENDEN AS VE ON VE.CODVEN = RC.CodeVen
left JOIN ABONOS AS AB on AB.FACTURA=TD.NRODCTO AND AB.TIPODCTOCA=TD.TIPODCTO
where TD.TIPODCTO in ('FU','FB','FC') and TD.CODCC=VE.CCOSTOS and VE.Interno=1
group by TD.BRUTO,TD.NRODCTO,VE.NOMESCALAFON
having sum(AB.VALOR)>=TD.BRUTO


y lo que necesito es que me sume el resultado de todos los resultados devuelto de esta consulta

intente sum para cada campo de cada subconsulta pero me tira error

Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

no se como hacer para que me sume todos lo resultados es solo una columna