12,394,552 members (73,047 online)
Rate this:
See more: , +
Hi All,

i have requirement like to Convert rows to columns in SQL server.

i have retrieved data like below:
```MatchId SelectionName   Odds
322	Home Win	1.33
322	Draw	        5.00
322	Away Win	9.00
322	Under 2.5	2.40
322	Over 2.5	1.53```
and want to convert like below:
```MatchId Home Win   Draw   Away Win   Under 2.5   Over 2.5
322	1.33	   5.00   9.00       2.40        1.53 ```
how can i do this?

Thanks,
KK
Posted 27-May-13 1:30am
kk20142K
Updated 27-May-13 1:33am
v2

Rate this:

## Solution 2

```Select MatchId,[Home Win],[Draw],[Away Win],[Under 2.5],[Over 2.5]
From TableName
PIVOT
(
SUM(Odds) For SelectionName in ([Home Win],[Draw],[Away Win],[Under 2.5],[Over 2.5])
) as pvttbl```
Happy Coding!
Arun Vasu 27-May-13 7:49am

+5!
Good..
Aarti Meswania 27-May-13 7:53am

Thank you! :)
Rate this:

## Solution 1

query for make columns into rows in ms sql server[^]

Rate this:

## Solution 3

Hello,

i got my result from below query.

```select * from (select MatchId,SelectionName,Odds From
#tmpMatchOdds) As P Pivot
(
Sum([odds]) For SelectionName In ([Home Win],[Draw],[Away Win],[Under 2.5],[Over 2.5])
)As pv```

Top Experts
Last 24hrsThis month
 OriginalGriff 465 ppolymorphe 285 Jochen Arndt 230 Richard Deeming 229 Richard MacCutchan 229
 OriginalGriff 5,783 Karthik Bangalore 2,337 ppolymorphe 2,290 F-ES Sitecore 1,852 Richard MacCutchan 1,627