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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call Decode Result In a Function

Status
Not open for further replies.

getjbb

MIS
Jun 4, 2003
139
0
0
US
I am during a select with a couple of decodes included. How can I use the result (tr.trans_type) from the first decode in function call (SUBSTANCES.get_desc) in the second decode statement.

SELECT TRANS_NUM,
sub.ACCOUNT,
TRANS_DATE,
DECODE( (trans_num is null AND tr.trans_type=6 AND item_code='C'), THEN 19
ELSE tr.trans_type
END) tr.trans_type,
DECODE (
show_first_desc,
'Y', description
|| ' '
|| SUBSTANCES.get_desc (trans_num, tr.trans_type),
DECODE (show_second, 'Y', description, NULL))
description
from transactions tr, substance sub
where transactions.account = substance.account;

getjbb
 
Getjbb,

There were a couple of syntax issues in your original code, and I've aligned the corrected code so that you are able to read it a bit better.

Regarding your question about how to refer to the results of the original DECODE: simply re-state that DECODE where you need it (as I have done, below):
Code:
SELECT TRANS_NUM
      ,sub.ACCOUNT
      ,TRANS_DATE
      ,DECODE(trans_num||tr.trans_type||item_code
             ,'6C',19
             ,tr.trans_type) trans_type
      ,DECODE (show_first_desc
              ,'Y',description||'  '||
                   SUBSTANCES.get_desc(trans_num
                                      ,DECODE(trans_num||tr.trans_type||item_code
                                             ,'6C',19
                                             ,tr.trans_type
                                             )
                                      )
              ,DECODE (show_second
                      ,'Y',description
                      ,NULL
                      )
              ) description
  from transactions tr, substance sub
 where tr.account = sub.account;
Let us know if this resolves your need.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
“People may forget what you say, but they will never forget how you made them feel.
 
SantaMufasa,

Thank you. This is what I needed.

getjbb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top