troubleshooting Question

Swap Rows / Cols in a SQL Server 2005 Query / View

Avatar of Soalga
Soalga asked on
Microsoft SQL Server 2005
4 Comments3 Solutions977 ViewsLast Modified:
I have a table under SQL Server 2005 with two columns (col1, col2) and this table have about 10 records, so the table look like this:

COL1        COL2
=============
val1          val_1
val2          val_2
...
valN          val_N

what's the best way to swap rows for cols to obtain some like this in a view:

val1     val2      ...   valN
====================
val_1   val_2   ...   val_N,

where the values of COL1 becomes the column names of the result, and the values of COL2 the values for each new column.
ASKER CERTIFIED SOLUTION
ptjcb

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros