How To Unpivot In Sql? (sap Hana) (columns To Rows)
I need to unpivot some data in SAP HANA. I set up an example table to try it out on, but I still can't get anywhere. The actual table contains 1000's of ID's and ~50 columns, but
Solution 1:
Creating a key-value store like table is the wrong thing to do in most situations that involve SQL databases. That said, with HANA SDI/SDQ (Smart data Integration/smart data quality) you can create a “flow graph” (basically a data transformation process) that does the pivot/unpivot operation without having to code much.
Solution 2:
Here is a solution that requires me to specify the column names and type conversions:
(Credit to jarlh for the union suggestion)
select"ID",
'Country'as"FieldName",
"COUNTRY"as"FieldValue"from#example
union all
select"ID",
'Name'as"FieldName",
"NAME"as"FieldValue"from#example
union all
select"ID",
'Balance'as"FieldName",
CAST("BALANCE"as NVARCHAR) as"FieldValue"from#example
Post a Comment for "How To Unpivot In Sql? (sap Hana) (columns To Rows)"