Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

String Concat - returning multiple rows in one string cocat row - response (3) by mika0815

$
0
0

 

If the number of elements you want to concatenate is low, you can do something like this:

 

sel

  databasename

 ,tablename

 ,max(case when rnk = 1 then        ColumnName else '' end) ||

  max(case when rnk = 2 then ',' || ColumnName else '' end) ||

  max(case when rnk = 3 then ',' || ColumnName else '' end) ||

  max(case when rnk = 4 then ',' || ColumnName else '' end) ||

  max(case when rnk = 5 then ',' || ColumnName else '' end) ||

  max(case when rnk = 6 then ',' || ColumnName else '' end) ||

  max(case when rnk = 7 then ',' || ColumnName else '' end) ||

  max(case when rnk = 8 then ',' || ColumnName else '' end) ||

/*** There're are more rows than expeted  ***/

  max(case when rnk > 8 then ',...' else '' end) as ConcatenatedRows

from

 (

  sel

    databasename

   ,tablename

   ,trim(columnName) as ColumnName

   ,rank() over (partition by databasename, tablename

                 order by columnid) as rnk

  from

    dbc.columns

  where databasename = 'dbc'

 ) dt

group by 1,2

order by 1,2

;

 

This is an example from Dieter Noeth: http://www.tek-tips.com/viewthread.cfm?qid=747901


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>