Solved

How do I pivot in a select statement

Posted on 2013-05-15
11
256 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 32

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 32

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
 
LVL 40

Expert Comment

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

Author Comment

by:GD_GRAY
ID: 39170983
2010
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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 38

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now