Solved

How do I pivot in a select statement

Posted on 2013-05-15
11
254 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

744 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

13 Experts available now in Live!

Get 1:1 Help Now