Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Issue in how to pivot!

$
0
0
Hello all,

Please see my attached file for my data layout in TSQL query. I am not sure how to convert several rows into columns as my detailed format. I heard the Pivot technique but I could get them in my issue.
This is my data t-sql query result into tempTable
SchoolId | Firstname | Lastname |Class | Subject | Score
--------------------------------------------------------------------
1 John Smith 6 Math 85
1 John Smith 6 Science 100
1 John Smith 6 English 85
2 Julie Chan 7 Geography 75
2 Julie Chan 7 Math 100
3 Sara West 8 Science 85
3 Sara West 8 English 90
...

I would like to covert my above data into the following order:

SchoolID | Firstname | Lastname | Class | Math | Science | English | Geography | etc…
------------------------------------------------------------------------------------------------
1 John Smith 6 85 100 85 NA
2 Julie Chan 7 100 NA NA 75
3 Sara West 8 NA 85 90 NA
...

Any expertise in TSQL query to help me out? I really appreciate your time. Thanks in advance.

Attached Files
File Type: doc This is my data tsql.doc (37.5 KB)

Viewing all articles
Browse latest Browse all 13329

Trending Articles