The context of the question is based on the following
ID | Group_Level | Group_Values
1 | Division | Value 1
2 | Department | Value 2
3 | Class | Value 3
should be pivoted into
ID | Division | Department | Class
1 | Value 1 | Value 2 | Value 3
2 | Value 1 | Value 2 | Value 3
Based on many searches and experiments I have done trying pivoting in Sybase ASE, there seems to be only support for pivoting when you know what the values can be.
For example,
select id,
max (case when group_level = 'Division' then Group_Values else null end) Division,
max (case when group_level = 'Department' then Group_Values else null end) Department,
max (case when group_level = 'Class' then Group_Values else null end) Class
from YourTable group by id
works when we know values of group_level. All the other answers I got doesn't work in Sybase ASE and were based on Sybase Anywhere or other DB.
So, Is there a way this can be done more generic when we don't know the values of that field in Sybase-ASE
The example and answer are taken from Pivoting in Sybase SQL Query?