[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL Table Transpose

Posted on 2007-04-09
7
Medium Priority
?
453 Views
Last Modified: 2012-06-22
Is there a command in sql to transpose a table?
0
Comment
Question by:kayhustle
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 18880039
By transpose do you mean a crosstab?

There is a command in SQL 2005 called PIVOT

In SQL 2000 there is are many workaround solutions. The best solution depends on your actual issue and what the realted systems are.


But basically a crosstab is best done in the front end, if you have one.
0
 
LVL 1

Author Comment

by:kayhustle
ID: 18880057
I've never heard the term cross tab, but I'll look in the PIVOT command.
0
 
LVL 23

Expert Comment

by:Racim BOUDJAKDJI
ID: 18881100
<<Is there a command in sql to transpose a table?>>
I am not familiar with that term.  Could you explain what you are expecting?
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 1

Author Comment

by:kayhustle
ID: 18883809
Transpose is when you take a table and flip it 45 degrees so that all the columns are now rows and all rows are now columns.
0
 
LVL 23

Expert Comment

by:Racim BOUDJAKDJI
ID: 18883914
<<Transpose is when you take a table and flip it 45 degrees so that all the columns are now rows and all rows are now columns.>>
Then indeed PIVOT/UNPIVOT is what you are looking for...

Hope this helps...
0
 
LVL 1

Author Comment

by:kayhustle
ID: 18884254
If I have
SELECT Date, Cost, Clicks, Impressions
FROM MyTable
GROUP BY Date

How can I pivot that statement to return each column as an individual Date?
Thanks
0
 
LVL 30

Accepted Solution

by:
nmcdermaid earned 1500 total points
ID: 18886833
OK. First thing is that wiht PIVOT you need to explicilty define the output columns. In other words you need to know which dates you want to show beforehand.

There are stored procedures around that will do this for you too.

But really you are much better off doing this in the user interface, not in the database.

Here is a link to a dynamic crosstab stord procedure:

http://weblogs.sqlteam.com/jeffs/articles/5120.aspx


Here is link backing up the fact that you should do this in the presentation layer:

http://weblogs.sqlteam.com/jeffs/archive/2005/05/12/5127.aspx
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

656 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