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!

decode

Status
Not open for further replies.

Bloke152

Programmer
Joined
Aug 9, 2005
Messages
123
Location
NO
I sure im not being very bright with this one but i cant work out how its bringing up the values it is. So could someone please explain to me what this line is doing. i thought i knew but i must be wrong!

Sum(decode(a.direction,'+',a.quantity,-a.quantity))
Thanks!
 
It is summing a.quantity while applying a sign (a.direction)
Code:
SQL> CREATE TABLE TESTIT (QUANTITY number, DIRECTION char(1));

Table created.

SQL> INSERT INTO TESTIT VALUES (10,'+')

1 row created.

SQL> INSERT INTO TESTIT VALUES (25,'+');

1 row created.

SQL> INSERT INTO TESTIT VALUES(1,'-');

1 row created.

SQL> SELECT Sum(decode(a.direction,'+',a.quantity,-a.quantity)) RESULT
  2* FROM TESTIT A
SQL> /

    RESULT
----------
        34

SQL>

Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
Author and Sole Proprietor of: Emu Products Plus
 
Thants great thanks, i was on the wrong track. Thanks for your help!
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top