Hi @ojm
Please check this query:
;WITH CTE1 AS
(
SELECT StudentName
,CONCAT(Class1Present,'/',Class1Absent) AS Class1
,CONCAT(Class2Present,'/',Class2Absent) AS Class2
,CONCAT(Class3Present,'/',Class3Absent) AS Class3
FROM #Test
),CTE2 AS
(
SELECT * FROM CTE1
UNPIVOT(Present_Absent FOR Class IN([Class1],[Class2],[Class3]))U
)
SELECT Class AS StudentName,[John],[Mary],[Tom],[Susan]
FROM CTE2
PIVOT(MAX(Present_Absent)FOR StudentName IN ([John],[Mary],[Tom],[Susan]))P
Best regards,
Cosmog Hong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.