0

Conver the Row into column

I am trying to convert the below data into column value and print the data.

Database : SQL server

1 Answers1

1

You can use conditional aggregation:

select id,
       max(case when attb_name = 'Job name' then value end) as job_name,
       max(case when attb_name = 'Created date' then value end) as created_date,
       max(case when attb_name = 'Created by' then value end) as created_by,
       max(case when attb_name = 'Job type' then value end) as job_type
from t
group by id;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • Thanks for you help, Actually my column not fixed, there are number of column, can you pls share me dynamic query – PANDURANG BHADANGE May 17 '20 at 13:21
  • Above table value getting after using below query SELECT _ID, ATTRB_NM, value FROM abc v WHERE v.type = 'BIGDATA' ORDER BY 1; ------------------------- MY ACTUAL QUERY IS Where condition so that, Aggregate function with group by clause getting Error – PANDURANG BHADANGE May 17 '20 at 13:33