How to write a query to convert colums into rows in sql?

Posted by Suneel161 under Sql Server on 4/6/2011 | Points: 10 | Views : 3578 | Status : [Member] | Replies : 2
Hi All.


i want a query for showing the columns in rows like,



f1 f2 f3....... f20 s1 s1 s3.......s20 w1 w2 w3.....20
A1 A2 A3.........A20 B1 B2 B3......... B20 C1 C2 C3.......C20

Result:
f1 A1
f2 A2
.
.
.
.
f20 A20
S1 B1
S2 B2
.
.
.
S20 B20




Responses

Posted by: SheoNarayan on: 4/6/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Are you looking at the example shown in below links ?

http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx a
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

Hope this helps!

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 4/6/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,
this is something called a pivot in sql... check the below link

http://stackoverflow.com/questions/1753551/sql-query-converting-rows-of-a-table-into-columns

Thanks
Karthik
www.f5Debug.net

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response