DBAsupport.com Forums - Powered by vBulletin
Results 1 to 8 of 8

Thread: SELECT (Urgent)

  1. #1
    Join Date
    Jul 2001
    Posts
    334
    I have num1 and num2. And I am subtracting num1 - num2
    e.g num1 - num2
    1000 - 500 = 500

    but what if values are:
    case1 1000 - -500 (num1 pos & num2 neg value) ??
    case2 -1000 - -500 (num1 neg & num2 neg value) ??
    case3 -1000 - 500 (num1 neg & num2 pos value) ??

    Can any one solve all 3 above cases in SELECT statement.

    Thanks


  2. #2
    Join Date
    Mar 2001
    Posts
    635
    Hi

    Try this

    select 1000 - -500 from dual;

    Regards
    Santosh

  3. #3
    Join Date
    Jul 2001
    Posts
    334
    The problem is

    select a,
    b,
    c,
    num1 - num2 d
    from test;


  4. #4
    Join Date
    Oct 2000
    Location
    Germany
    Posts
    1,185
    Perhaps I missed the point.

    For the sake of clarity, you might want to try using parentheses in your code and see if that helps.

    Good luck.
    David Knight
    OCP DBA 8i, 9i, 10g

  5. #5
    Join Date
    Mar 2001
    Posts
    635
    Hi

    Is this what you are looking for

    12:17:33 SQL> l
    1* select (1000 - -500) A , (-1000 - -500) B, (-1000 - 500) C from dual
    12:17:34 SQL> /

    A B C
    --------- --------- ---------
    1500 -500 -1500

    Regards,
    Santosh

  6. #6
    Join Date
    Jul 2001
    Posts
    334
    Thanks Santosh and Dk, But lets say if

    select num1 - num2 from dual;
    select 324 - -324 from dual;
    In this case it will return 648 i do not want this

    What I want is 0.


    Thanks

  7. #7
    Join Date
    Oct 2000
    Location
    Germany
    Posts
    1,185
    Your intent is not clear.

    324 - - 324 = 648 according to my arithmetic book.

    You might want to try using the ABS or absolute value function to get what you want. I am not what that is.

    Good luck
    David Knight
    OCP DBA 8i, 9i, 10g

  8. #8
    Join Date
    Jul 2001
    Posts
    334
    Yes Dk, Thanks it works fine by using ABS.


    Thanks for your help.

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