3
Answers

Is it possible to convert multiple rows to a single column?

Is it possible to convert multiple rows to single column?
For Ex,
I have table like this,
       id   name  subname   marks
        1   abc    C         10
        1   abc    JAVA      20
        1   abc    DAA       30
        2   xyz    C         30
        2   xyz    JAVA      20
        2   xyz    DAA       10
          In this case the rows should converted into columns and the subname should come only once as column in the table like this.

       id  name   C      JAVA     DAA
        1   abc  10       20       30
        2   xyz  30       20       10
            Is it possible? If possible please help me....
 

Answers (3)

0
Photo of Govinda Rajulu Yemineni
NA 1.5k 233.2k 9y
Hi, 
 
SELECT [ID],[Name],[C],[JAVA],[DAA]
FROM
(
      SELECT [ID],[Name],[subname],[marks] FROM tbl_student_marks_Details
) AS S
PIVOT
(
      SUM([marks])
      FOR [subname] IN([C],[JAVA],[DAA])
) AS PivotTable
ORDER BY [ID]
 
0
Photo of Pankaj  Kumar Choudhary
NA 29.8k 3.1m 9y
Hello @sureshma you can visit these links
 
http://www.mssqltips.com/sqlservertip/2914/rolling-up-multiple-rows-into-a-single-row-and-column-for-sql-server-data/
http://raresql.com/tag/merge-or-combine-multiple-rows-records-to-single-column-record-with-comma-delimiters/ 
0
Photo of Rajeesh Menoth
NA 24.7k 629.6k 9y