Ver Mensaje Individual
  #3 (permalink)  
Antiguo 14/03/2013, 13:43
Avatar de chris225
chris225
 
Fecha de Ingreso: octubre-2012
Ubicación: Medellin
Mensajes: 149
Antigüedad: 11 años, 6 meses
Puntos: 2
Respuesta: problema con funcion con rango de fechas

Cita:
Iniciado por Libras Ver Mensaje
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 :)
no funciono :(