locked
Divide by zero error encountered. RRS feed

  • Question

  • User2067508032 posted

    When I put data=0 error appear pls help me ASAP       Yell

    SELECT CONVERT(VARCHAR(11),CaptureTime,106)'CaptureTime',Type,CASE WHEN Unit='g/L' THEN (data1* 0.02586) " +
                            "ELSE data1" +
                            "END As data1, " +

                            "CASE WHEN Unit='g/L' THEN nullif(data2* 0.02586,0) " +
                            "ELSE data2" +
                            "END As data2, " +

                            "CASE WHEN Unit='g/L' THEN nullif(data3* 0.02586,0) " +
                            "ELSE data3" +
                            "END As data3, " +

                            "CASE WHEN Unit='g/L' THEN nullif(data1* 0.02586,0) / nullif(data2* 0.02586,0) " +
                            "ELSE (data1/data2)" +
                            "END As Ratio," +

                            "CASE WHEN Unit='g/L' THEN 'ml/L' " +
                            "ELSE 'ml/L' " +
                            "END As data, " +

                            "CASE WHEN Unit='g/L' THEN (data4* 0.01129) " +
                            "ELSE data4" +
                            "END As data4" +
                            "FROM something where Type ='DATA' and ID='" + Session["name"].ToString() + "' Order By CONVERT(DateTime, CaptureTime,101)  DESC"

    Tuesday, October 30, 2012 5:20 AM

Answers

  • User2067508032 posted

    I solve like that

    CASE WHEN Unit='ml/L' THEN nullif(data1* 38.7,0) / nullif(data2* 38.7,0) " +
                            "ELSE (data1/nullif(data2,0))" +
                            "END As Ratio,"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 30, 2012 6:09 AM

All replies