Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 22 Aug 2008 @ 10:26:16 GMT


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


Subj:   Re: How Can I Avoid Repeating an Expression?
 
From:   Anomy Anom

<-- Anonymously Posted: Thu, 21 Aug 2008 13:21 -->

I believe either of these will work...

     sel substr(date,1,7) Yr_Month,
        Svc_Ownr_Cd,
        Bucket,
        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  100 * (curr_bal - cl_amt) / cl_amt
                 when <= 10 then '(2)  <= 10%'
                 when <= 15 then '(3)  <= 15%'
                 when <= 20 then '(4)  <= 20%'
                 when <= 25 then '(5)  <= 25%'
                 else '(6)  > 25%'
               end
        end as OL_Pct,
        count(1) Number
     from  Table
     where ...
     group by 1,2,3,4

OR

     sel substr(date,1,7) Yr_Month,
        Svc_Ownr_Cd,
        Bucket,
         100 * (curr_bal - cl_amt) / cl_amt (Named mycalc),
        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 mycalc <= 10 then '(2)  <= 10%'
                 when mycalc <= 15 then '(3)  <= 15%'
                 when mycalc <= 20 then '(4)  <= 20%'
                 when mycalc <= 25 then '(5)  <= 25%'
                 else '(6)  > 25%'
               end
        end as OL_Pct,
        count(1) Number
     from  Table
     where ...
     group by 1,2,3,4


     
  <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