
Max(case when columnname = 'LastName' then value end) LastName,

Max(case when columnname = 'PostalCode' then value end) PostalCode,

Max(case when columnname = 'Amount' then value end) Amount, Max(case when columnname = 'FirstName' then value end) Firstname, If you do not want to use the PIVOT function, then you can use an aggregate function with a CASE expression: select Select = STUFF((SELECT ',' + QUOTENAME(ColumnName)Įxec sp_executesql Demo. If you have an unknown number of columnnames that you want to transpose, then you can use dynamic SQL: DECLARE AS AS NVARCHAR(MAX) In SQL Server you can use the PIVOT function to transform the data from rows to columns: select Firstname, Amount, PostalCode, LastName, AccountNumberįor columnname in (Firstname, Amount, PostalCode, LastName, AccountNumber)

There are several ways that you can transform data from multiple rows into columns.
