Results 1 to 9 of 9
  1. #1
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121

    Divided by Zero Error please fix it

    SUM(O.MENGE/((A.ZZVND_TIER_QTY)*(A.ZZVND_TIE_QTY))) AS [Pallet1],


    SUM(O.MENGE/((E.ZZVND_TIER_QTY)*(E.ZZVND_TIE_QTY))) AS [Pallet2]


    Above statement is working fine if (tier_qty* tie_qty) is not zero . if tie and tire qty zero then it give me error msg. divided by zero error.


    IN below statement I am trying to avoid divide by zero error it give me an error message "invalid syntax" what i m missing ? Kindly help. please note that all are integer.





    SUM(O.MENGE/NULLIF((A.ZZVND_TIER_QTY)*(A.ZZVND_TIE_QTY)),0) AS [Pallet1],

    SUM(O.MENGE/NULLIF((E.ZZVND_TIER_QTY)*(E.ZZVND_TIE_QTY)),0) AS [Pallet2]

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    1st create a query Q1, that creates the divisor result.
    Now make Q2, using Q1 where > 0 , and do the sum (all these will not fail)
    Now make Q3, using Q1 where = 0 , but produce 0. or some other error msg.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In Access, there is no such function named "NullIf".
    Code:
    SUM(O.MENGE/NULLIF((A.ZZVND_TIER_QTY)*(A.ZZVND_TIE_QTY)),0) AS [Pallet1],
    SUM(O.MENGE/NULLIF((E.ZZVND_TIER_QTY)*(E.ZZVND_TIE_QTY)),0) AS [Pallet2]
    Maybe you mean "NZ()"???
    Code:
    SUM(O.MENGE/NZ((A.ZZVND_TIER_QTY)*(A.ZZVND_TIE_QTY)),1) AS [Pallet1],
    SUM(O.MENGE/NZ((E.ZZVND_TIER_QTY)*(E.ZZVND_TIE_QTY)),1) AS [Pallet2]
    And I would change the zero to a one, so you don't get a divide by zero error.


    Even then you could get a zero in the divisor. Maybe:
    Code:
    SUM(O.MENGE/IIF(NZ((A.ZZVND_TIER_QTY)*(A.ZZVND_TIE_QTY)),1)=0,1,NZ((A.ZZVND_TIER_QTY)*(A.ZZVND_TIE_QTY)),1)) AS [Pallet1],
    SUM(O.MENGE/IIF(NZ((E.ZZVND_TIER_QTY)*(E.ZZVND_TIE_QTY)),1)=0,1,NZ((E.ZZVND_TIER_QTY)*(E.ZZVND_TIE_QTY)),1)) AS [Pallet2]
    

  4. #4
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121
    Quote Originally Posted by ssanfu View Post
    In Access, there is no such function named "NullIf".
    Code:
    SUM(O.MENGE/NULLIF((A.ZZVND_TIER_QTY)*(A.ZZVND_TIE_QTY)),0) AS [Pallet1],
    SUM(O.MENGE/NULLIF((E.ZZVND_TIER_QTY)*(E.ZZVND_TIE_QTY)),0) AS [Pallet2]
    Maybe you mean "NZ()"???
    Code:
    SUM(O.MENGE/NZ((A.ZZVND_TIER_QTY)*(A.ZZVND_TIE_QTY)),1) AS [Pallet1],
    SUM(O.MENGE/NZ((E.ZZVND_TIER_QTY)*(E.ZZVND_TIE_QTY)),1) AS [Pallet2]
    And I would change the zero to a one, so you don't get a divide by zero error.


    Even then you could get a zero in the divisor. Maybe:
    Code:
    SUM(O.MENGE/IIF(NZ((A.ZZVND_TIER_QTY)*(A.ZZVND_TIE_QTY)),1)=0,1,NZ((A.ZZVND_TIER_QTY)*(A.ZZVND_TIE_QTY)),1)) AS [Pallet1],
    SUM(O.MENGE/IIF(NZ((E.ZZVND_TIER_QTY)*(E.ZZVND_TIE_QTY)),1)=0,1,NZ((E.ZZVND_TIER_QTY)*(E.ZZVND_TIE_QTY)),1)) AS [Pallet2]
    

    I am using SQL server management studio 2012.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    How about

    Case When Whatever = 0 Then 1 Else Whatever End
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121
    Quote Originally Posted by pbaldy View Post
    How about

    Case When Whatever = 0 Then 1 Else Whatever End
    SUM(O.MENGE/CASE WHEN (A.ZZVND_TIER_QTY)*(A.ZZVND_TIE_QTY)=0 THEN 1 ELSE ((A.ZZVND_TIER_QTY)*(A.ZZVND_TIE_QTY)) AS [Pallet1],
    SUM(O.MENGE/
    CASE WHEN (E.ZZVND_TIER_QTY)*(E.ZZVND_TIE_QTY)=0 THEN 1 ELSE ((E.ZZVND_TIER_QTY)*(E.ZZVND_TIE_QTY)) AS [Pallet2]



    still giving me error msg divide by zero. what I am missing

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Unless I'm blind the parentheses are unbalanced, and you don't have the End included.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    adnancanada is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2010
    Posts
    121

    Thumbs up

    Quote Originally Posted by pbaldy View Post
    Unless I'm blind the parentheses are unbalanced, and you don't have the End included.
    Thank you very pbaldy. It is working now yes parentheses were unbalanced. Thank you very much.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 17
    Last Post: 01-23-2016, 02:08 AM
  2. Running Sum divided by Month Total
    By kwooten in forum Reports
    Replies: 7
    Last Post: 05-16-2013, 10:20 AM
  3. Total divided by weekdays in a month
    By normie in forum Access
    Replies: 1
    Last Post: 03-22-2012, 07:09 PM
  4. 0 divided by 0 = impossible..
    By LanieB in forum Queries
    Replies: 13
    Last Post: 01-03-2012, 05:24 PM
  5. Replies: 1
    Last Post: 02-01-2010, 06:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums