Skip to Content
avatar image
Former Member

Error SQL (Divide by zero error encountered)

Que tal, me podrían apoyar con este query, por mas que lo he modificado no logro quitar ese error:

SELECT 
T0.NOMES, 
T0.SERIESNAME AS 'SUCURSAL', 
T0.SLPCODE, 
T0.SLPNAME, 
T0.CardCode, 
T0.CardName,
T1.U_IMPORTE 'OBJETIVO MES', 
T1.U_OBJETIVOMU 'OBJETIVO MU',
 
SUM(ISNULL(T0.TOTALSINIVA,0)) AS 'VENTA NETA', SUM(ISNULL(T0.UTILIDAD,0)) AS 'MU', 


CASE WHEN SUM(T0.TOTALSINIVA)=0 THEN 0 ELSE


(SUM(ISNULL(T0.UTILIDAD,0))/SUM(ISNULL(T0.TOTALSINIVA,0)))*100 END AS 'PORCENTAJE MU',


(SELECT ISNULL(SUM(T5.DOCTOTAL),0) AS 'VENCE' FROM OINV T5


WHERE  T5.CardName=T0.CARDNAME AND MONTH(T5.DocDueDate)=T0.NOMES AND T5.SlpCode=T0.SLPCODE) AS 'SI VENCE',


(SELECT ISNULL(SUM(T5.DocTotal)-(SUM(T5.DOCTOTAL)-SUM(PaidToDate)) ,0) AS 'RECUPERADO' FROM OINV T5


WHERE  T5.CardName=T0.CARDNAME AND MONTH(T5.DocDueDate)=T0.NOMES AND T5.SlpCode=T0.SLPCODE) AS 'SF RECUPERADO'






FROM  VENTAS_OBJETIVOS T0 LEFT JOIN CONCENTRADO_OBJETIVOS T1  ON 
T0.SERIESNAME=T1.U_SUCURSAL AND T0.NOMES=T1.U_MES1 AND T0.SLPCODE=T1.U_IDVENDEDOR
WHERE T0.SERIESNAME<>'SI'
GROUP BY T0.NOMES, T0.SERIESNAME, T1.U_IMPORTE, T1.U_OBJETIVOMU, T0.SLPCODE, T0.SLPNAME, T0.CardCode, T0.CardName
ORDER BY T0.SeriesName, T0.SlpName, T0.CardCode

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Apr 26 at 07:33 AM

    Hola

    yo cambiaría esto:

    CASE WHEN ISNULL(SUM(T0.TOTALSINIVA),0) = 0 THEN 0 ELSE

    Un saludo

    Agustín

    Add comment
    10|10000 characters needed characters exceeded