I have an Excel file as a source for my data which looks like this:
ColumnName  |Value
----------------------------
OrderNumber |PO-000576632
OrderDate   |2018-09-16
Delivery    |2018-09-22
Currency    |USD
TotalValue  |8006.34
Seller      |SupplierName
GLN         |000098 --this value is dynamic
Buyer       |CustomerName
GLN         |001592 --this value is dynamic
DeliverTo   |DeliveryAddress
GLN         |5940477481122 --this value is dynamic
Having the information in this structure, the only way to use further this information in SQL is by using PIVOT relational operator. I managed somehow to get to the desired output, but since there are 3 GLN columns name, I could use only the first one in that list. Is there any way to rename those columns before using them in PIVOT?
Statement
SELECT
      OrderNumber, OrderDate, Delivery,
      Currency, TotalValue, Seller, GLN,
      Buyer, DeliverTo  
FROM
(
SELECT 
      value, columnname
FROM  MyTable
) MyTable
PIVOT
(
MAX(value)
FOR ColumnName IN(    OrderNumber, OrderDate, Delivery,
      Currency, TotalValue, Seller, GLN,
      Buyer, DeliverTo))
piv
I did some research and find something promising here, but didn't helped me. Any tips would be helpful! Thanks
 
    