Explain UNPIVOT with example in SQL Server.
Explain UNPIVOT with example in SQL Server.
I completed my post-graduation in 2013 in the engineering field. Engineering is the application of science and math to solve problems. Engineers figure out how things work and find practical uses for scientific discoveries. Scientists and inventors often get the credit for innovations that advance the human condition, but it is engineers who are instrumental in making those innovations available to the world. I love pet animals such as dogs, cats, etc.
Khushi Singh
13-Jan-2025UNPIVOT, which works with SQL Server is used to turn columns into rows. This is especially valuable in cases when you have to normalize your data or when you prefer to transform a table consisting of columns containing similar data into a table with more rows and one column.Syntax of
UNPIVOT:value_column: The column into which the values of the columns in the transformation process will be migrated.name_column: The column that will hold the names of the original columns as well.column_list: The name of the columns that would be unpivoted.Use Cases:
Data Normalization: Converting a wide dataset into a tall format for easier analysis.
Reporting: Generating row-based reports from columnar data.
Integration: Preparing data for systems that require row-based data instead of columnar.
By using
UNPIVOT, you can easily transform your data into the desired format.