|    
			
				26/03/2013, 09:42
			
			
			  | 
  |   |  |  |  |  Fecha de Ingreso: octubre-2012 Ubicación: Medellin 
						Mensajes: 149
					 Antigüedad: 13 años Puntos: 2 |  | 
  |  Respuesta: La subconsulta ha devuelto más de un valor  
  ya lo arregle muchas gracias de todas maneras por la ayuda aca les paso las funciones que hice 
 este es el que calcula
 
 SELECT DISTINCT
 case when VE.Interno=0
 then
 (select top 1(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, @pfecha,@pfecha1) between Desde and Hasta))
 * (select (PorcReca/100) from GS_ConfEscal where Nombre=VE.NOMESCALAFON)
 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=@pinterno
 group by TD.BRUTO,TD.NRODCTO,VE.NOMESCALAFON--,TD.CODVEN,TD.TIPODCTO,VE.Interno
 having  sum(AB.VALOR)>=TD.BRUTO)
 else
 case when VE.Interno=1
 then
 (Select top 1(TD.BRUTO - isnull((select SUM(CANTIDAD*VALORUNIT) from MVTRADE where TIPODCTONC in ('FC') and NUMFACTNC=TD.NRODCTO),0))
 * (select (PorcReca / 100) from GS_ConfEscal where Nombre=VE.NOMESCALAFON) 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
 where TD.TIPODCTO IN ('FC') and TD.CODVEN=VE.CODVEN and VE.Interno=@pinterno) end end as total
 from venden as VE, Trade as TD where (TD.FECHA >= @pfecha) AND (TD.FECHA1 <= @pfecha1) and VE.Interno=@pinterno
 
 y este le envia los parametros
 
 select GS_FN_ConsultarComisiones.CODVEN,sum(comisionconno  tacredito)as Comision,Nombre,DiasFactura from GS_FN_ConsultarComisiones (@pfecha,@pfecha1)
     |