21 June 2018        Add to Favorites   Report

Teradata : Transpose columns to rows

Scenario - Need to convert columns in a table to rows

Source table Query :

select * from <table>

Answer set :

JOB1JOB2
16138


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:

Col1    Col2

JOB1    161
JOB2    38


Solution:

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

SELECT 'Job1', job1 FROM TABLE
UNION ALL 
SELECT 'Job2', job2 FROM TABLE
Copied