Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Dynamically pivoting a table in SAP HANA

In this thread

http://scn.sap.com/thread/3527126

OP asks for an option to pivot a table in HANA.

The solution works, but I am interested in a dynamic solution so that it automatically adapts to the structure of the table and the columns names do not need to be created manually everytime a table needs to be pivoted...something like this for MySQL: http://buysql.com/mysql/14-how-to-automate-pivot-tables.html

SET @sql = NULL;

SELECT

  GROUP_CONCAT(DISTINCT

    CONCAT(

      'MAX(IF(property_name = ''',

      property_name,

      ''', value, NULL)) AS ',

      property_name

    )

  ) INTO @sql

FROM properties;

SET @sql = CONCAT('SELECT item_id, ', @sql, ' FROM properties GROUP BY item_id');

I have read the SCN forum and I do not want to do anything involving a calculation view or work with Data Services. Is there a way to do that? 

Tags:
Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question