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

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.