Search code examples
hana

Display custom columns in HANA Query


I would like to know if there is a HANA/SQL query that can change the below data:

U_User  U_Calendar
John    Calendar 1
James   Calendar 3
Mike    Calendar 1
Carol   Calendar 1
Jethro  Calendar 2
Harry   Calendar 2

into something like this?

Calendar 1  Calendar 2  Calendar 3
John        Jethro      James
Mike        Harry   
Carol       

Thanks for the help.


Solution

  • For up to SPS 11, SAP HANA doesn't provide a PIVOT command on SQL level. Unconfirmed comments say that the command is already in the backlog but not yet scheduled for any release.

    This article summarizes alternatives for PIVOT: http://scn.sap.com/thread/3527126

    If you have exactly 3 calendars then you can get away with a static SQL script but for a dynamic number of calendars, you have to use dynamic SQL. The link above also has examples for both, but it gets messy really fast.