Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Thu, 08 Jun 2006 @ 09:57:31 GMT


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


Subj:   Re: SQL to Normalize Columns to Rows
 
From:   Dunweber, Ole

Hello,

How about this one - no transient journal, one pass over the data:

     insert into NewTable
     select CustId,
            CASE
               WHEN(Col001 IS NOT NULL) THEN 1
               WHEN(Col002 IS NOT NULL) THEN 2
               ...
               WHEN(Col250 IS NOT NULL) THEN 250
            END AS TypeId,
            SUM(CASE
                   WHEN(Col001 IS NOT NULL) THEN Col001
                   WHEN(Col002 IS NOT NULL) THEN Col002
                   ...
                   WHEN(Col250 IS NOT NULL) THEN Col250
                END) AS Sales_Amt
       from ExistingTable
      group by 1,2

Best Regards,

Ole Dunweber
Coop Nordic



     
  <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