Sukhada Vader

Sukhada Vader

  • NA
  • 64
  • 28.6k

Use Of PIVOT in SQL Server without aggregate function

Mar 15 2018 2:53 AM
I want to change rows into column as it is.. means without any aggregate function on coming answer. like i have 2 columns as ExamType and Obtained marks 1st will contains the values like
 
ExamTypeCode    ObtainedMarks
1                                  18
2                                  20
3                                  45
1                                  15
2                                  22
3                                  47
 
and i want the data like following without any aggregate function
 
1 2 3
----------------
18 20 45
15 22 47
 
I have tried the following query , its giving me ans but not like which i want
  1. SELECT *  
  2. FROM  
  3. (  
  4. SELECT StudentRegCode,ExamTypeCode,ObtainedMark FROM StudentSubjectMark  
  5. AS SourceTable  
  6. PIVOT  
  7. (MIN([ObtainedMark]) FOR [ExamTypeCode] IN([1],[3],[4])) AS PivotTable;  

Answers (2)