Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I pivot in a select statement

Posted on 2013-05-15
11
Medium Priority
?
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
11 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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.

610 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