Donate

How To Unpivot In SQL Server With Example

Given the following records below, you may want to show them in a vertical manner instead of horizontal view of columns.

To achieve the desired result, you use UNPIVOT clause in your query.
1
2
3
4
5
6
7
8
Use testdatabase
Go
SELECT [Subject],
       Grade
FROM StudentReportCard 
UNPIVOT (Grade FOR [Subject] IN (English, Math, Literature, Biology)) 
        AS U_SubjectGrade
WHERE StudentId = 1
Screenshot
Unpivot In SQL Server Example

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations