Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Thu, 26 Mar 2009 @ 15:40:12 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Sub query in case statement
 
From:   Anderson, Dirk

The example you provided does not need a subselect....you can get the answer without a subselect....

     SEL ORG_CD,
     CASE
        WHEN ORG_LEVEL = 'SUB_LOB' THEN 'Y'
        ELSE 'N'
     END

     FROM hr_nonhr a
     ;

Or, you could do a self-join...

     SEL A.ORG_CD,
     CASE
        WHEN b.ORG_CD IS NOT NULL THEN 'Y'
        ELSE 'N'
     END

     FROM hr_nonhr a
     LEFT OUTER JOIN hr_nonhr b
        ON a.ORG_CD = B.ORG_CD
       AND B.ORG_LEVEL='SUB_LOB'
     ;

Dirk Anderson
Architect
Enterprise Information Management



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 27 Dec 2016