How to get table values as a column heading (****) | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

How to get table values as a column heading (****)

Hello,
My requirement is like the following. There is a student table with the following details. Table : Student
—————-
Student Subject Score
1 Eng 70
1 Math 80
1 Science 90
2 Eng 65
2 Math 75
2 Science 85 I want output in the following manner with a Single Select statement.This is possible with PIVOT command in SQL Server 2005. But I don’t know how to achieve the same in SQL Server 2000. Can anyone help me?? This is very urgent…. This question was asked by Microsoft. Student Eng Math Science
1 70 80 90
2 65 75 85
Niladri
Check out crosstab in the 2000 BOL. —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs
Ich unterstuetze PASS Deutschland e.V. http://www.sqlpass.de)
Read about Cross-Tab Reports in sql server help file Madhivanan Failing to plan is Planning to fail
Hello All,
Thanks for your referrence. I have got the query. Here I am submitting the finaly query to get
the desired ouput SELECT id,
SUM(CASE subject WHEN ‘eng’ THEN Score ELSE 0 END) AS Eng,
SUM(CASE subject WHEN ‘math’ THEN Score ELSE 0 END) AS Math,
SUM(CASE subject WHEN ‘science’ THEN Score ELSE 0 END) AS Science
FROM student
GROUP BY id Thanks to all Niladri
Also, if you use Reports, make use of its cross tab feature if it allows Madhivanan Failing to plan is Planning to fail
]]>