|
|
Archives of the TeradataForum
Message Posted: Thu, 08 Jun 2006 @ 09:57:31 GMT
Subj: | | Re: SQL to Normalize Columns to Rows |
|
From: | | Dunweber, Ole |
Hello,
How about this one - no transient journal, one pass over the data:
insert into NewTable
select CustId,
CASE
WHEN(Col001 IS NOT NULL) THEN 1
WHEN(Col002 IS NOT NULL) THEN 2
...
WHEN(Col250 IS NOT NULL) THEN 250
END AS TypeId,
SUM(CASE
WHEN(Col001 IS NOT NULL) THEN Col001
WHEN(Col002 IS NOT NULL) THEN Col002
...
WHEN(Col250 IS NOT NULL) THEN Col250
END) AS Sales_Amt
from ExistingTable
group by 1,2
Best Regards,
Ole Dunweber
Coop Nordic
| |