I have been looking for an answer for a few hours about my problem.
My current table:
StudentName Course Correct Wrong Blank Score
-------------------------------------------------
Student1 Math 38 2 0 95
Student1 English 45 5 0 90
...
Student2 Math 38 2 0 95
Student2 English 45 5 0 90
What I want is:
Math English
StudentName Correct Wrong Blank Score Correct Wrong Blank Score
Student1 38 2 0 95 45 5 0 90
Student2 38 2 0 95 45 5 0 90`
...
SELECT dbo.tbl_Students.StudentName,
dbo.tbl_CourseCategories.CourseCategory,
dbo.tbl_GeneralTestsScores.Correct,
dbo.tbl_GeneralTestsScores.Wrong,
dbo.tbl_GeneralTestsScores.NotAnswered,
dbo.tbl_GeneralTestsScores.Score
FROM
dbo.tbl_AcademicTermsStudents
INNER JOIN
dbo.tbl_Students ON dbo.tbl_AcademicTermsStudents.StudentID = dbo.tbl_Students.StudentID
INNER JOIN
dbo.tbl_GeneralTestsScores
INNER JOIN
dbo.tbl_CourseCategories
ON dbo.tbl_GeneralTestsScores.CourseCategoryID = dbo.tbl_CourseCategories.CourseCategoryID
ON dbo.tbl_AcademicTermsStudents.StudentID = dbo.tbl_GeneralTestsScores.StudentID
Order By StudentName
I searched many pages any could not end up with a solution.
Thanks.
Edit: I would also accept the following as a solution...
StudentName Math_C Math_W Math_B Math_S English_C English_W English_B English_S
Student1 38 2 0 95 45 5 0 90
Student2 38 2 0 95 45 5 0 90`
You can achieve this with a 'double pivot' by adding a new unique column for each subject/score combination before pivoting.
Here's a static example, you can easily turn this into a dynamic pivot to cater for more classes. You could also put your original query in a CTE, insert into a temp table or inline as required - I've used a single temp table for clarity.
Hope this helps.