|
|
Archives of the TeradataForum
Message Posted: Fri, 09 Dec 2005 @ 19:57:58 GMT
Subj: | | Re: How to Convert Records into Columns |
|
From: | | Dieter Noeth |
Raju Chakinala wrote:
| I have the situation that needs to convert the one record into multiple records, for example I am getting employee and his 12 months salary
information as one record wise, I need to insert these 12 months salary information as 12 records ( one record for each month) Data in source
table: | |
select emp_id, 1, jan_rev as revenue
from source
union all
select emp_id, 2, feb_rev as revenue
from source
union all
....
or use a helper table with values from 1 to 12:
select
emp_id,
dt.i,
case dt.i
when 1 then jan_rev
when 2 then feb_rev
...
end
from source cross join
(select i from helper where i between 1 and 12) dt
Dieter
| |