Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I've learned more from your forums in 3 days than 3 months at school and on the job combined..."

Geography

Where in the world do Tek-Tips members come from?
getjbb (MIS)
27 Feb 12 18:33
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
SantaMufasa (TechnicalUser)
27 Feb 12 19:23
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.

santaMufasa
(aka Dave of Sandy, Utah, USA)
"People may forget what you say, but they will never forget how you made them feel."

getjbb (MIS)
27 Feb 12 20:49
SantaMufasa,

Thank you. This is what I needed.

getjbb

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close