[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I pivot in a select statement

Posted on 2013-05-15
11
Medium Priority
?
280 Views
Last Modified: 2013-05-25
Can anyone show me the syntax to simply pivot the results of a table.What I would like to get
0
Comment
Question by:GD_GRAY
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 34

Expert Comment

by:Big Monty
ID: 39168867
have you looked at MSDN's documentation?

http://msdn.microsoft.com/en-us/library/ms177410(v=sql.105).aspx
0
 
LVL 34

Expert Comment

by:Big Monty
ID: 39168869
0
 

Author Comment

by:GD_GRAY
ID: 39169526
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
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
LVL 41

Expert Comment

by:Sharath
ID: 39170633
What is your SQL Server version?
0
 

Author Comment

by:GD_GRAY
ID: 39170983
2010
0
 

Author Comment

by:GD_GRAY
ID: 39171063
Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (X64)
0
 
LVL 41

Expert Comment

by:Sharath
ID: 39173340
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
 

Author Comment

by:GD_GRAY
ID: 39174445
[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
 
LVL 39

Accepted Solution

by:
Aaron Tomosky earned 2000 total points
ID: 39182157
0
 

Author Closing Comment

by:GD_GRAY
ID: 39196550
Thank you, I was sure I viewed every link on stack but I missed that one.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question