Teradata : Transpose columns to rows

Scenario - Need to convert columns in a table to rows

Source table Query :

\n\n
select * from <table>\n
\n\n

Answer set :

\n\n
JOB1JOB2
16138


\n\n

We need to transform the above answer set as below. We need to get the column name entry in each row with their corresponding values as shown below:

\n\n
Col1    Col2\n\nJOB1    161\nJOB2    38\n
\n\n


Solution:

if you need to get the column names as values you need to write them as literals:

\n\n
SELECT 'Job1', job1 FROM TABLE\nUNION ALL \nSELECT 'Job2', job2 FROM TABLE\n

nVector

posted on

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds