Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

How do I pivot in a select statement

Can anyone show me the syntax to simply pivot the results of a table.What I would like to get
0
GD_GRAY
Asked:
GD_GRAY
  • 5
  • 2
  • 2
  • +1
1 Solution
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
have you looked at MSDN's documentation?

http://msdn.microsoft.com/en-us/library/ms177410(v=sql.105).aspx
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
0
 
GD_GRAYAuthor Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
SharathData EngineerCommented:
What is your SQL Server version?
0
 
GD_GRAYAuthor Commented:
2010
0
 
GD_GRAYAuthor Commented:
Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (X64)
0
 
SharathData EngineerCommented:
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
 
GD_GRAYAuthor Commented:
[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
 
Aaron TomoskySD-WAN SimplifiedCommented:
0
 
GD_GRAYAuthor Commented:
Thank you, I was sure I viewed every link on stack but I missed that one.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now