12,304,652 members (64,259 online)
Rate this:
See more: , +
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?

Posted 1-Jan-13 23:29pm
Edited 1-Jan-13 23:31pm
v2
CHill60 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:

## Solution 2

Aarti Meswania 2-Jan-13 6:58am

that is a useful article
thank you!
:)
Rate this:

## 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```
Aarti Meswania 2-Jan-13 6:56am

it's also working
thank you! :)
__TR__ 2-Jan-13 8:50am

You're welcome.
Rate this:

## 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!

Top Experts
Last 24hrsThis month
 Sergey Alexandrovich Kryukov 330 OriginalGriff 281 Karthik Bangalore 175 Peter Leow 144 BillWoodruff 135
 OriginalGriff 10,327 ppolymorphe 5,966 CHill60 5,867 Karthik Bangalore 5,566 Richard MacCutchan 5,357