How do I pivot in a select statement

Can anyone show me the syntax to simply pivot the results of a table.What I would like to get
GD_GRAYAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Aaron TomoskyConnect With a Mentor Technology ConsultantCommented:
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
have you looked at MSDN's documentation?

http://msdn.microsoft.com/en-us/library/ms177410(v=sql.105).aspx
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
GD_GRAYAuthor Commented:
Yes thank you, but I am not getting anyplace with the docs. I can't seem to make anything work since I need the ID or the Models to show as the column headers and I have no way of knowing the models in advance or what the ID is all of the docs just confuse me.
0
 
SharathData EngineerCommented:
What is your SQL Server version?
0
 
GD_GRAYAuthor Commented:
2010
0
 
GD_GRAYAuthor Commented:
Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (X64)
0
 
SharathData EngineerCommented:
Basically you want to transpose rows into columns and columns into rows.
Couple of questions.
1. Why do you want data in that way? Why I am asking is, if you have hundreds of records, converting them into columns is not a good idea. BTW, how many records/columns do you have in your table?
2. You have an ID column? Is it a unique value incremented by 1 for each record?
0
 
GD_GRAYAuthor Commented:
[1.] Its for a report displayed as a grid, and in printing out the report most of the columns coz the report to extend way beyond the boundaries. Plus ++ the look is much cleaner with fewer pages.

[2.] Table has 96 columns, but each query will be a group of them the largest group of 23 and it will be for a single instance. "SELECT column's3, 4, 5 FROM myTable WHERE column2='X' "

Column1 is the ID column and it is a unique value incremented by 1 for each record.
0
 
GD_GRAYAuthor Commented:
Thank you, I was sure I viewed every link on stack but I missed that one.
0
All Courses

From novice to tech pro — start learning today.