Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 09 Dec 2005 @ 19:57:58 GMT


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


Subj:   Re: How to Convert Records into Columns
 
From:   Dieter Noeth

Raju Chakinala wrote:

  I have the situation that needs to convert the one record into multiple records, for example I am getting employee and his 12 months salary information as one record wise, I need to insert these 12 months salary information as 12 records ( one record for each month) Data in source table:  


     select emp_id, 1, jan_rev as revenue
     from source
     union all
     select emp_id, 2, feb_rev as revenue
     from source
     union all
     ....

or use a helper table with values from 1 to 12:

     select
        emp_id,
        dt.i,
        case dt.i
          when 1 then jan_rev
          when 2 then feb_rev
          ...
        end
     from source cross join
     (select i from helper where i between 1 and 12) dt

Dieter



     
  <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