Pivoting in Sybase ASE
<p>The context of the question is based on the following</p>

<pre><code>ID | Group_Level | Group_Values

1 | Division | Value 1
2 | Department | Value 2
3 | Class | Value 3
</code></pre>

<p>should be pivoted into</p>

<pre><code>ID | Division | Department | Class

1 | Value 1 | Value 2 | Value 3
2 | Value 1 | Value 2 | Value 3
</code></pre>

<p>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.</p>

<p>For example, </p>

<pre><code>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
</code></pre>

<p>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.</p>

<p>So, Is there a way this can be done more generic when we don't know the values of that field in Sybase-ASE</p>

<p>The example and answer are taken from 
<a href="https://stackoverflow.com/questions/8114032/pivoting-in-sybase-sql-query">Pivoting in Sybase SQL Query?</a></p>