I have a table which have fields like fieldname and fieldvalue. I am trying to turn this table into another format.
For example, I have below table with fields and values:
x
-----------------------------
| Fieldname | Fieldvalue |
-----------------------------
| Matnr | 001 |
| Werks | 1000 |
| Statu | 01 |
-----------------------------
I want to create a internal table with the following column names and values like this:
-------------------------------
| Matnr | Werks | Statu |
-------------------------------
001 1000 01
How can I do this?
Advertisement
Answer
You can use conditional aggregation:
select max(case when fieldname = 'Matnr' then fieldvalue end) as matnr,
max(case when fieldname = 'Werks' then fieldvalue end) as Werks,
max(case when fieldname = 'Statu' then fieldvalue end) as Statu
from t;