Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I have data like below...
VB
data rowno colno
---------------
abc   1     1
12    1     2
xyz   2     1
89    2     2


now I want Output
col1  col2
------------
abc   12
xyz   89  


How can i do this
using pivot or any other way?

please help :)
Posted
Updated 1-Jan-13 23:31pm
v2
Comments
CHill60 2-Jan-13 6:18am    
Have a look at the answer at http://stackoverflow.com/questions/6349568/sql-pivot-table. Hope it helps

I have solved it
hope it will useful to them having same problem

SQL
select [1] as col1, [2] as col2 
from tbl

PIVOT
(
 max(data)
  FOR colno
  IN (	[1],[2]  )
) PivotTable


Happy coding!
:)
 
Share this answer
 
Read my article about dynamic pivotting here[^]
 
Share this answer
 
Comments
Aarti Meswania 2-Jan-13 6:58am    
that is a useful article
thank you!
:)
Here is an approach without using Pivot
SQL
DECLARE @T TABLE (data VARCHAR(50), rowno INT, colno INT)
---------------
INSERT INTO @T
SELECT 'abc', 1, 1 UNION ALL
SELECT '12', 1, 2 UNION ALL
SELECT 'xyz', 2, 1 UNION ALL
SELECT '89', 2, 2


--SELECT data, RowNo, ColNo FROM @T

SELECT Col1, Col2 FROM
(
    SELECT Data AS Col1, RowNo, ColNo FROM @T
    WHERE ColNo = 1
) A
INNER JOIN
(
    SELECT Data AS Col2, RowNo, ColNo FROM @T
    WHERE ColNo = 2
) B ON A.RowNo = B.RowNo
 
Share this answer
 
Comments
Aarti Meswania 2-Jan-13 6:56am    
it's also working
thank you! :)
__TR__ 2-Jan-13 8:50am    
You're welcome.

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