On SQL 2005 or later, you can use PIVOT operator like this:SELECT
*
FROM
#t1
PIVOT
( MAX(col2) FOR col1 IN ([1],[2],[3]))P
That obviously is not scalable. WHen there are unknown number of columns to pivot, people use DYNAMIC PIVOT - see Madhivanan's blog here: http://beyondrelational.com/modules/2/blogs/70/posts/10840/dynamic-pivot-in-sql-server-2005.aspx