0

My table structure is like this:

enter image description here

But I want output as follows:

English  hindi  telugu  drawing
-------  ----- ------- --------
english  hindi  telugu  drawing
paper2   paper1  paper2  drawing2

I want to display subjectid as column headings and paper names as rows.

Please help me.

Giorgi Nakeuri
  • 35,155
  • 8
  • 47
  • 75
  • 1
    Possible duplicate of [Convert Rows to columns using 'Pivot' in SQL Server](http://stackoverflow.com/questions/15931607/convert-rows-to-columns-using-pivot-in-sql-server) – GSerg Nov 09 '16 at 09:30

1 Answers1

0

You could try a query like the following one if classid does not matter.

SELECT [English], [Hindi],[Telugu],[Drawing]
FROM 
(
   SELECT ROW_NUMBER() OVER (PARTITION BY SubjectId ORDER BY PaperName) AS rownum, SubjectId, PaperName 
   FROM T
   GROUP BY SubjectId, PaperName 
)AS base
PIVOT
( MAX(PaperName) FOR SubjectId IN ([English], [Hindi],[Telugu],[Drawing])) AS pvt;
Fivi
  • 1
  • 1