May 2025 Discount: Comprehensive Database Performance Health Check | Testimonials

Home
  • Consulting
  • Training
  • Free Videos
  • All Articles
    • Interview Questions and Answers
    • SQL Tips and Tricks
    • SQL Performance
    • SQL Puzzle
    • Big Data
    • Blog Stats
    • SQL Books
    • Search SQLAuthority
  • Downloads
  • Hire Me
  • Health Check
pivotunpivot

SQL SERVER – Exploring PIVOT and UNPIVOT

October 24, 2023
Pinal Dave
SQL Tips and Tricks
PIVOT, Query Rewrite, UNPIVOT

The SQL Server PIVOT and UNPIVOT operators are powerful tools that provide an easy way to transform your data in SQL.

Read More

SQL SERVER – Example of PIVOT UNPIVOT Cross Tab Query in Different SQL Server Versions

October 1, 2008
Pinal Dave
SQL, SQL Server, SQL Tips and Tricks
MVP, PIVOT, UNPIVOT
Transforming rows to columns (PIVOT/CROSS TAB) and columns to rows (UNPIVOT) may be one of the common requirements that all of us must have seen several times in our programming life. SQL Server 2005 introduced two new operators: PIVOT and UNPIVOT that made writing cross-tab queries easier. My friend and…
Read More

SQL SERVER – PIVOT and UNPIVOT Table Examples

June 7, 2008
Pinal Dave
SQL, SQL Server, SQL Tips and Tricks
PIVOT, SQL Joins, SQL Scripts, UNPIVOT
I previously wrote two articles about PIVOT and UNPIVOT tables. I really enjoyed writing about them as it was interesting concept. One of the Jr. DBA at my organization asked me following question. “If we PIVOT any table and UNPIVOT that table do we get our original table?” I really…
Read More

SQL SERVER – UNPIVOT Table Example

May 29, 2008
Pinal Dave
SQL, SQL Server, SQL Tips and Tricks
PIVOT, SQL Function, SQL Scripts, UNPIVOT
My previous article SQL SERVER – PIVOT Table Example encouraged few of my readers to ask me question about UNPIVOT table. UNPIVOT table is reverse of PIVOT Table. USE AdventureWorks GO CREATE TABLE #Pvt ([CA] INT NOT NULL, [AZ] INT NOT NULL, [TX] INT NOT NULL); INSERT INTO #Pvt ([CA],…
Read More

SQL SERVER – PIVOT Table Example

May 22, 2008
Pinal Dave
SQL Tips and Tricks
PIVOT, SQL Scripts, SQL Server, UNPIVOT

This is quite a popular question and I have never wrote about this on my blog. A Pivot Table can automatically sort, count, and total the data stored in one table or spreadsheet and create a second table displaying the summarized data. The PIVOT operator turns the values of a specified column into column names, effectively rotating a table.

Read More
  • SQL Interview Q & A
  • Testimonials
  • Search
  • Privacy Policy

© 2006 – 2025 All rights reserved. pinal @ SQLAuthority.com

Go to mobile version