-5

I have this Project Class table which consists of Project ID,and there are 21 categories tagged to this Project ID and class codes.

enter image description here

The Project ID along with their class categories and class codes should be in one line (in the new table) when queried with the Project_ID and there shouldn't be any multiple instances.Something like this,

Project ID    Class_category1  Class_category2......So on
Value         Class_Code1      Class_Code 2........So on

How can I achieve this and using which function?

Veijo
  • 264
  • 2
  • 9
M_P
  • 11
  • 1

1 Answers1

1

You should use SQL PIVOT syntax and may have to use dynamic pivot if you don't have the list of all class_category data

Your query should be like below

select * 
from 
PA_PROJECT_CLASSES
pivot
(
    max(class_code) 
    for class_category in 
    (
    [254 codes],
    [330 codes],
    -- your categories in proper [] syntax
    )
)p
DhruvJoshi
  • 17,041
  • 6
  • 41
  • 60