-2

For better understanding lets assume a table StudentMarks which contains data as

StudentMarks_Table_Data

I am trying to insert data into another table StudentDetail for which i want the output to look like this

StudentDetail_Table_Data

I could only think of a solution where I would make three different inserts into the StudentDetail Table based on the three different columns.

INSERT INTO StudentDetail (StudentID, Subject, Marks)
SELECT 
sm.StudentID,
"Math",
sm.Math
FROM StudentMarks sm Order By sm.StudentID

INSERT INTO StudentDetail (StudentID, Subject, Marks)
SELECT 
sm.StudentID,
"Science",
sm.Science
FROM StudentMarks sm Order By sm.StudentID

And similarly for English.

Please suggest any alternate or more efficient solution to solve this issue.. Thanks

Jens
  • 63,364
  • 15
  • 92
  • 104
  • Does this answer your question [Unpivot with column name](https://stackoverflow.com/questions/19055902/unpivot-with-column-name)? – Dordi May 16 '22 at 10:18

0 Answers0