Sunday, March 11, 2012

convert the rows into column

I want to convert the row value as column name

example:-->

value ratio

3 4.16666666666
1 1.31578947368
0 0
0 0

To :->

value ratio ratio1 ratio2 ratio3

3 4.166 1.315 0 0

any ideas?

If you are running sql server 2005 you can do it with a pivot table. If sql 2000, I think you have to code it yourself. See

http://jdixon.dotnetdevelopersjournal.com/pivot_table_data_in_sql_server_2000_and_2005.htm

http://www.sqlservercentral.com/articles/Advanced+Querying/pivottableformicrosoftsqlserver/2434/ (registration required)

http://sqlserver2000.databases.aspfaq.com/how-do-i-create-a-cross-tab-or-pivot-query.html

No comments:

Post a Comment