0

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?

Community
  • 1
  • 1
Sharukh Mohamed
  • 55
  • 1
  • 12
  • See http://stackoverflow.com/questions/39652613/sybase-sql-self-join-multiple-rows/39735610#39735610 – RobV Sep 27 '16 at 23:01
  • 1
    The issue again is that he knows that there 3 columns to fill so he does a 3 way self join. The requirement here is that we don't know the number of joins we want I.e. the number of colums – Sharukh Mohamed Sep 27 '16 at 23:03

0 Answers0