Results 1 to 6 of 6

Thread: SQL query - 10g

  1. #1
    Join Date
    Aug 2008
    Posts
    464

    Unanswered: SQL query - 10g

    Hi guys

    Hope some one can advise!

    I have a query e.g.,

    Code:
    select 
    A/((B+C)+D)
    from table
    How can I implement:

    If (B+C) is -ve or <0 or C > B, then treat (B+C)=0

    Regards
    Shajju

  2. #2
    Join Date
    Jun 2004
    Posts
    796
    Provided Answers: 1
    So you want to potentially divide something by zero? Not recommended!
    90% of users' problems can be resolved by punching them - the other 10% by switching off their PCs.

  3. #3
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    CASE or DECODE might be your choices (the first one is simpler to manage, though).

  4. #4
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Just fun with arithmetic(not recommendeable).
    A/((B+C+ABS(B+C))/2+D)

  5. #5
    Join Date
    Aug 2008
    Posts
    464
    Thanks guys. I used:

    A/(DECODE(SIGN(B-C),-1,0,(B-C)))

    Regards
    Shajju

  6. #6
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    "D" seems to be missing. The way you put it now, you'd better handle divide-by-zero.

Posting Permissions

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