13,448,933 members (54,971 online)
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
Updated 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

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

## Solution 2

Aarti Meswania 2-Jan-13 6:58am

that is a useful article
thank you!
:)

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

Top Experts
Last 24hrsThis month
 OriginalGriff 355 Maciej Los 175 John Simmons / outlaw programmer 146 Jochen Arndt 140 Richard Deeming 130
 OriginalGriff 4,597 Maciej Los 2,592 CPallini 1,632 ppolymorphe 1,449 Richard MacCutchan 1,441