Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arithmetic Comparison in Select Clause

Status
Not open for further replies.

thermidor

Programmer
Nov 28, 2001
123
US
Hi All:

I would like to know how to accomplish an arithmetic comparison in a select clause. I am joining two tables. I need to compare two values that exist at the join and say if value A is =< value B then String A else String B, and I need to do this in my Select clause.

Can anyone explain how to do this?

TIA,
Sven
 

In your WHERE clause you may use:
Code:
decode(sign(B - A),-1,B,A)
Example:
Code:
SQL> create table test_bc (a number, b number);

Table created

SQL> insert into test_bc values(1,3);

1 row inserted

SQL> insert into test_bc values(5,5);

1 row inserted

SQL> insert into test_bc values(10,7);

1 row inserted

SQL> select decode(sign(B - A),-1,B,A) from test_bc;

DECODE(SIGN(B-A),-1,B,A)
------------------------
                       1
                       5
                       7

Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
My website: Emu Products Plus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top