Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Teradata Equivalent to ORACLE UNPIVOT Command

Status
Not open for further replies.

terrordata2

Programmer
Aug 19, 2012
1
Hello Teradata Experts,

The following query was posted in the Teradata Forum back in 2010, but it didn't receive any replies. I am attempting to do exactly the same thing as part of a large Data Conversion Exercise (25 Tables, 40 Columns per Table). If it could also be done using a Stored Procedure - that would be ideal. Let's assume that I only know the name of the KEY Column - but not any of the others. Note that I do not want to use UNION ALL.
_________________________________________________________________________________________________________________________

To convert the columns to rows , I was trying UNPIVOT in Oracle 11g like given below

KEY C1 C2 C3
--- ----- ----- -----
r1 v1 v2 v3
r2 v1 v2
r3 v1 v3
r4 v1
r5 v2 v3
r6 v2
r7 v3
r8


select key, source, val
from
t UNPIVOT INCLUDE NULLS
( VAL FOR( SOURCE ) IN
( C1 AS 'C1',
C2 AS 'C2',
C3 AS 'C3'
)
)
order by key, source ;


Do we have any function in Teradata like UNPIVOT to achieve the same results ( without using union all) ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top