Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/03/2013, 13:31
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: problema con funcion con rango de fechas

Código SQL:
Ver original
  1. ALTER FUNCTION GS_FN_ConsultarComisiones
  2. (
  3. @pfecha DATE,
  4. @pfecha1 DATE
  5. )
  6. RETURNS TABLE
  7. AS
  8. RETURN
  9. (
  10. SELECT TD.Fecha AS Desde,TD.fecha1 AS Hasta,VE.CODVEN,VE.INTERNO, DATEDIFF(DAY, TD.Fecha,TD.fecha1) AS DiasFactura,
  11. (TD.BRUTO* (RC.PorcReca/100))AS ValorRecaudo,
  12. ((TD.BRUTO* (RC.PorcReca/100))*(ES.PorcReca/100)) AS ComisionsinNotaCredito,
  13.  
  14. CASE WHEN VE.INTERNO = 1 THEN SUM(((TD.BRUTO*(RC.PorcReca/100))-((MV.cantidad * MV.valorunit)) * (ES.PorcReca/100))) ELSE (TD.BRUTO*(RC.PorcReca/100))-((MV.cantidad * MV.valorunit)) * (ES.PorcReca/100) END AS COMISION
  15. FROM TRADE TD
  16. INNER JOIN MVTRADE MV ON MV.NRODCTO = TD.NRODCTO AND MV.ORIGEN = TD.ORIGEN AND MV.TIPODCTO = TD.TIPODCTO
  17. CROSS JOIN GS_Recaudo RC
  18. CROSS JOIN gs_confescal ES
  19. INNER JOIN TIPODCTO T ON T.origen=MV.origen
  20. INNER JOIN VENDEN VE ON VE.CODVEN=TD.CODVEN
  21. WHERE (td.FECHA=@pfecha AND td.FECHA1=@pfecha1) AND
  22. (DATEDIFF(DAY, @pfecha,@pfecha1) BETWEEN RC.desde AND RC.hasta)GROUP BY TD.BRUTO,RC.PorcReca,MV.tipodcto,MV.NRODCTO,MV.tip odctonc,ES.PorcReca,MV.cantidad,MV.valorunit,TD.Fe cha,TD.Fecha1
  23. ,mv.numfactnc,VE.CODVEN,VE.INTERNO
  24. )

prueba con eso :)
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me