Click to See Complete Forum and Search --> : SELECT (Urgent)
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
santoshym
08-13-2001, 01:11 PM
Hi
Try this
select 1000 - -500 from dual;
Regards
The problem is
select a,
b,
c,
num1 - num2 d
from test;
dknight
08-13-2001, 01:15 PM
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.
santoshym
08-13-2001, 01:18 PM
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,
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
dknight
08-13-2001, 01:37 PM
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
Yes Dk, Thanks it works fine by using ABS.
Thanks for your help.