Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 22 Aug 2008 @ 10:32:00 GMT


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


Subj:   Re: How Can I Avoid Repeating an Expression?
 
From:   frank.p.oconnor

Hi

You can use a derived table and name an expression (see column a below):

     SELECT
     yr_month,
     Svc_Ownr_Cd,
     Bucket,
     ol_pct,
     counter

     FROM
     (
     SEL SUBSTR(DATE,1,7) Yr_Month,
     Svc_Ownr_Cd,
     Bucket,
     100 * * (curr_bal - cl_amt) / cl_amt AS a

     CASE
     WHEN cl_amt = 0 AND curr_bal > cl_amt THEN '(0) CL=0 & Bal>CL'

     WHEN curr_bal <= cl_amt THEN '(1) not OL'
     ELSE CASE
          WHEN a <= 10 THEN '(2) <= 10%'
          WHEN a <= 15 THEN '(3) <= 15%'
          WHEN a <= 20 THEN '(4) <= 20%'
          WHEN a <= 25 THEN '(5) <= 25%'
          ELSE '(6) > 25%'

          END

     END AS OL_Pct,

     COUNT(1) Number

     FROM TABLE

     WHERE ...

     ) derivedtable (yr_month, Svc_Ownr_Cd, Bucket, a, ol_pct, counter)

     GROUP BY 1,2,3,4

Cheers

Frank

Frank O'Connor
ES&T
Enterprise Systems and Technology



     
  <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: 15 Jun 2023