Results 1 to 8 of 8

Thread: Simple math issue

  1. #1

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Simple math issue

    I have a database that supplies numbers for some math.

    The math is of the form A plus B over C

    A + B
    ------
    C

    However sometimes C is 0.

    Therefore I need a formula that will work normally for all values greater than nothing but result in 0 when C is 0. Is this do able?

    Thanks guys.
    ?
    'What's this bit for anyway?
    For Jono

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Have a system :

    A+B
    C , for C>0
    0 , for C=0


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    Originally posted by manavo11
    Have a system :

    A+B
    C , for C>0
    0 , for C=0
    I was hopeing that there was some formula with a bit of +1, -1 etc that would simply by pass div by zero... I hate editing the raw SQL as it is nested six selects deep.
    ?
    'What's this bit for anyway?
    For Jono

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    You'll need an equivalent of iif (instant if).

    iif(c=0,0,(a+b/c))

    either that or put the formula into a sub query with a linkable ID filtered on the c<>0.


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  5. #5

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    Originally posted by Ecniv
    You'll need an equivalent of iif (instant if).

    iif(c=0,0,(a+b/c))

    either that or put the formula into a sub query with a linkable ID filtered on the c<>0.

    Vince
    Probably yes. I don't want to face what access does to nested queries when you open them back up... but yes at least you have illiminated non-options.
    ?
    'What's this bit for anyway?
    For Jono

  6. #6
    Lively Member Something Else's Avatar
    Join Date
    Nov 2003
    Location
    Where Humboldt Intersects Carlson
    Posts
    99
    Hmmm,
    Well:

    (1\(C+1)) + C

    Results in 1 if C = 0, or C when C > 0.

    But you now need a multiplier that = 0 when C = 0, or 1 when C <> 0.

    Hmmm,

    K = (1\(C+1))+C

    So,

    When C = 0, then K = 1
    When C > 0, then K = C

    So:

    C/K = 0 when C = 0,
    C/K = 1, when C > 0.

    Therefore:

    (C/K)*(A+B)/(K)
    where
    K = (1\(C+1))+C
    hmmm,
    Is that Right?


    -Lou
    Last edited by Something Else; Jul 22nd, 2004 at 06:35 PM.
    no soap...radio -mendhak

    I understand...just a little...
    No comprende, it's a riddle
    - Wall of Voodoo-Mexican Radio

  7. #7

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    Looks hopefull
    ?
    'What's this bit for anyway?
    For Jono

  8. #8

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    I loved the math however smarty pants in the office next door may have jsut shown us all up "why not simply ignore all values of 0 and never use it as +0 and 0 not added is the same"

    beasty!
    ?
    'What's this bit for anyway?
    For Jono

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width