Click here to Skip to main content
16,012,082 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My table structure is like this:

web 1000
classic 2000
platinum 3000

& i want it like

web classic platinum
1000 2000 3000


can anyon suggest on this
Posted

1 solution

You need pivot your data:
http://archive.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=PIVOTData[^]
http://msdn.microsoft.com/en-us/library/ms177410%28v=sql.90%29.aspx[^]

Let say, your table contains 2 columns: Goods and Price (no identity kolumn), than your query should looks like:
SQL
SELECT RowNo, [web], [classic], [platinum]
FROM(
    SELECT ROW_NUMER() OVER (ORDER BY Price) RowNo, Goods, Price
    FROM YourTable
    ) AS DT
PIVOT(SUM(Price) FOR [RowNo] IN ([web], [classic], [platinum])) AS PT


How to create dynamic columns for goods ([web], [classic], [platinum])?
https://www.simple-talk.com/blogs/2007/09/14/pivots-with-dynamic-columns-in-sql-server-2005/[^]
 
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