rahul
rahul

Reputation: 59

Modify columns to rows in SQL Server

How to convert columns to rows in SQL Server?

For example I have table with 31 columns as numbers from 1 to 31.

PFA screenshot for the same.

These no should range from 1 to 31 in row format.

Upvotes: 0

Views: 80

Answers (1)

Alan Burstein
Alan Burstein

Reputation: 7918

You are trying to unpivot, you can use T-SQL UNPIVOT covered here: https://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx

Or, "An Alternative (Better?) Method to UNPIVOT (SQL Spackle)" by Dwain Camps found here: http://www.sqlservercentral.com/articles/CROSS+APPLY+VALUES+UNPIVOT/91234/

Upvotes: 1

Related Questions