|
-
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
-
Hi
Try this
select 1000 - -500 from dual;
Regards
Santosh
-
The problem is
select a,
b,
c,
num1 - num2 d
from test;
-
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
-
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
-
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
-
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
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|