12,070,351 members (57,014 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 2-Jan-13 0:29am
Edited 2-Jan-13 0:31am
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
 CHill60 275 OriginalGriff 173 Dave Kreskowiak 155 Richard Deeming 130 Sascha Lefèvre 110
 Dave Kreskowiak 2,276 OriginalGriff 1,624 Richard MacCutchan 1,535 CHill60 1,179 CPallini 1,122