Pivot a table with SQL
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


Pivot a table with SQL Expand / Collapse
Author
Message
Posted 4/12/2005 3:42:57 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 5/10/2008 8:36:20 AM
Posts: 8, Visits: 2
Does anyone have a good way to pivot a table when there is a variable amount of columns? I know that it can be done with a CASE statement, but that is tedious.
Post #1285
Posted 4/27/2006 10:20:58 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 5/10/2008 8:36:20 AM
Posts: 8, Visits: 2
It seems if I need to know the number of columns that I will need in these solutions. I would potentially need 100 columns convert from rows. Do you have any other thoughts?
Post #4041
Posted 4/28/2006 9:21:43 AM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 8/3/2006 2:56:00 PM
Posts: 13, Visits: 1
The only way to do what you are asking about is with dynamic SQL. If you wanted a pivot showing sales by department by year, you might not know how many departments or years there are. You would need a query to return all of your departments, and the iterate through that query to build sql strings for each line. Then you add each line to your query.

The real issue is how to handle the data once you build the query. If you are using something like .NET you can programatically output your data by looping through the columns or using AutoGenerateColumns = True. If you are using something like PL/SQL and Cursors, it is almost impossible.
Post #4047
Posted 6/19/2008 2:37:56 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/7/2008 2:56:19 PM
Posts: 3, Visits: 13
I am looking for a way to pivot as well. Several threads point to this thread as having an answer. The forum also shows 8 replies to this thread but I only see 3?
Post #11934
Posted 8/7/2008 8:45:11 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 8/8/2008 10:11:08 AM
Posts: 2, Visits: 5

i have similar question,
how you put rows to column

1 a
1 b
1 c
2 a
2 b
2 c

as
1 a b c
2 a b c

thansk you


kunny
Post #12472
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 2 ( 2 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 11:51pm

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.188. 10 queries. Compression Disabled.