Teradata SQL - Is it possible to take each line item and turn into column headers.

Culwatrnca11 used Ask the Experts™
I have this code which displays each DX number in one column.  I would like these to show in 5 different columns as the headers, is that possible?

      when dx.line = 1 then 'DX_1'      
      when dx.line = 2 then 'DX_2'      
            when dx.line = 3 then 'DX_3'      
            when dx.line = 4 then 'DX_4'      
            when dx.line = 5 then 'DX_5'      
            else 'N/A'      
end as "DX_Line"
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
EE Topic Advisor
Most Valuable Expert 2014
Awarded 2013
Typically you want to show some other value under each heading, but you give no clue as to what.

The most conventional way to "pivot data" if to use GROUP BY and aggregate functions such as MAX() e.g.

,  max(case when dx.line = 1 then somevaluehere end) DX_1
,  max(case when dx.line = 2 then somevaluehere end) DX_2
,  max(case when dx.line = 3 then somevaluehere end) DX_3
FROM sometables

{+ multiple edits, sorry)
Culwatrnca11Data Analyst


Thanks PortletPaul, this was very helpful.  I was able to obtain a report utilizing this format and the usage of max(case when...  to create a sub subquery in my existing report.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial