Solved

How do I pivot in a select statement

Posted on 2013-05-15
11
261 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
11 Comments
 
LVL 33

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 33

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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 40

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 40

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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

809 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