Convert columns into rows in SQL Server using VALUES and UNPIVOT

Converting columns into rows in SQL Server  is not a new thing, we often face this kind of scenarios. Lets say, there are values in different columns within a table and you want to perform some aggregations on those columns combining them all together or you may want them in a row fashion to do so. Let’s convert the columns into rows using VALUES and UNPIVOT operator.

columns-into-rows-in-sql-server

Populating Data:

Using VALUES:

 Using UNPIVOT:

columns-into-rows-plan-in-sql-server
 

Prasad Sahoo

Prasad Sahoo, is an enthusiast of Microsoft technologies in general and a passionate database professional, mainly focusing on SQL Server performance tuning and business intelligence. He has contributed a long time of his career working on SQL Server and other RDBMS. If he is not busy with SQL stuff then he must be watching some Hollywood movies.

One thought on “Convert columns into rows in SQL Server using VALUES and UNPIVOT

  • August 29, 2016 at 8:06 am
    Permalink

    how to convert the dynamic excel columns of pivot value before doing unpivot or values

    Reply

Leave a Reply

%d bloggers like this: