Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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....
Posted
Updated 12-Jun-15 18:08pm

1 solution

Yes you can do it and what you are looking for is Pivot relational operator.

Here are some links that help you learn PIVOT and come up with a solution for your case.

CodeProject Tip:
Simple Way To Use Pivot In SQL Query[^]

http://blog.sqlauthority.com/2008/06/07/sql-server-pivot-and-unpivot-table-examples/[^]

https://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900