Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Thu, 04 Aug 2005 @ 18:11:07 GMT


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


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

<-- Anonymously Posted: Thursday, August 04, 2005 12:47 -->

I would try something like this:

Regards, Paul

     Create volatile Table t1 As (
     Select 'Lesand' Last , 'Danny' Frst , 1 Codes
     ) with data
      On commit preserve rows ;

     Insert Into t1
     Select 'Lesand' , 'Danny' , 2 ;
     Insert Into t1
     Select 'Lesand' , 'Danny' , 3 ;
     Insert Into t1
     Select 'Benedi', 'Eric' , 7 ;
     Insert Into t1
     Select 'Benedi', 'Eric' , 14 ;

     Create volatile Table t2 As (
     Select t1 . last , frst , codes , csum( 1 , last || frst, codes ) Seq
     Group By last , frst
     ) with data
      On commit preserve rows
     ;

     Select a . last , a . frst
     ,
     Case When c . codes is Null
             Then a . codes || ',' || b . codes
      Else a . codes || ',' || b . codes || ',' || c . codes
      End codes

     From (
     Select *
     From t2
     Where seq = 1 ) a
     Left Join (
     Select *
     From t2
     Where seq = 2) b
      On a . last = b . last
      And a . frst = b . frst
     Left Join (
     Select *
     From t2
     Where seq = 3 ) c
      On a . last = c . last
      And a . frst = c . frst  ;


     
  <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