Skip to content
Advertisement

SQL Server Transpose FieldValue as FieldName

SQL Server Transpose , FieldValues as FieldNames:

Hello All, I have a tricky request for all of you.

I have a table with the following data

I can use pivot to transpose, but I want the result to be

Is it possible to achieve this using pivot without using XML ?

Thank you in advance.

Advertisement

Answer

You can try to use condition aggregate function

SQLFIDDLE

if you want to create your columns dynamically you can try to use dynamical pivot.

create your SQL statement and make condition aggregate function by connecting SQL string. then use execute it Dynamically.

sqlfiddle

Result

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement