• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

SQL Table Transpose

Is there a command in sql to transpose a table?
0
kayhustle
Asked:
kayhustle
  • 3
  • 2
  • 2
1 Solution
 
nmcdermaidCommented:
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
 
kayhustleAuthor Commented:
I've never heard the term cross tab, but I'll look in the PIVOT command.
0
 
Racim BOUDJAKDJIDatabase Architect - Dba - Data ScientistCommented:
<<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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
kayhustleAuthor Commented:
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
 
Racim BOUDJAKDJIDatabase Architect - Dba - Data ScientistCommented:
<<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
 
kayhustleAuthor Commented:
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
 
nmcdermaidCommented:
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
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

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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