Convert rows into columns for huge rows in Teradata

sel
        databasename
       ,tablename
       ,trim(((rnk / 8) * 8) + 1 (format '999')) || ' to ' ||
        trim(((rnk / 8) + 1) * 8 (format '999')) as ColumnNumber
       ,max(case when rnk mod 8 = 0 then ColumnName else '' end) ||
        max(case when rnk mod 8 = 1 then ',' || ColumnName else '' end) ||
        max(case when rnk mod 8 = 2 then ',' || ColumnName else '' end) ||
        max(case when rnk mod 8 = 3 then ',' || ColumnName else '' end) ||
        max(case when rnk mod 8 = 4 then ',' || ColumnName else '' end) ||
        max(case when rnk mod 8 = 5 then ',' || ColumnName else '' end) ||
        max(case when rnk mod 8 = 6 then ',' || ColumnName else '' end) ||
        max(case when rnk mod 8 = 7 then ',' || ColumnName else '' end) as
     Columns
     from
       (
        sel
          databasename
         ,tablename
         ,trim(columnName) as ColumnName
         ,rank() over (partition by databasename, tablename
                       order by columnid) -1 as rnk
        from
          dbc.columns
        where databasename = 'dbc'
       ) dt
     group by 1,2,3
     order by 1,2,3
     ;