Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Thu, 04 Aug 2005 @ 18:10:13 GMT


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


Subj:   Re: How to Concatenate Column Values using SQL/Macros
 
From:   bhull

I have done this before using this approach (this has not been syntax checked):

     select last
           ,first
           ,max(first_code) || max(second_code) || max(third_code) ||
     ...etc., etc. until the max.
     from
     (select last
            ,first
            ,case when csum(1, code asc) = 1 then code else '' end         as
     first_code
            ,case when csum(1, code asc) = 2 then ',' || code else '' end  as
     second_code
            ,case when csum(1, code asc) = 3 then ',' || code else '' end  as
     third_code
            ,  ...etc., etc. until the max number ...
        from tab1
        group by 1,2) DT1
     group by 1,2;

This method assumes that you do have a maximum number of codes. If that is not the case, this will not work.

Hope this helps.


Thanks,

Barry



     
  <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