Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I have data like below...
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 Smile | :)
Posted 2-Jan-13 0:29am
Edited 2-Jan-13 0:31am
v2
Comments
CHill60 at 2-Jan-13 6:18am
   
Have a look at the answer at http://stackoverflow.com/questions/6349568/sql-pivot-table. Hope it helps
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Read my article about dynamic pivotting here[^]
  Permalink  
Comments
Aarti Meswania at 2-Jan-13 6:58am
   
that is a useful article
thank you!
:)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Here is an approach without using Pivot
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
  Permalink  
Comments
Aarti Meswania at 2-Jan-13 6:56am
   
it's also working
thank you! :)
__TR__ at 2-Jan-13 8:50am
   
You're welcome.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I have solved it
hope it will useful to them having same problem
 
select [1] as col1, [2] as col2 
from tbl
 
PIVOT
(
 max(data)
  FOR colno
  IN (	[1],[2]  )
) PivotTable
 
Happy coding!
Smile | :)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100