Dynamic select Scripts / Pivot

November 24, 2008 at 02:16:05
Specs: AIX5.3, 4/4
Hi This is my script.

SELECT T$ITEM,
SUM(CASE WHEN T$YEAR=2005 THEN T$AUPP$1 ELSE 0 END) AS "2005 JAN",
SUM(CASE WHEN T$YEAR=2005 THEN T$AUPP$2 ELSE 0 END) AS "2005 FEB",
SUM(CASE WHEN T$YEAR=2005 THEN T$AUPP$3 ELSE 0 END) AS "2005 MARCH",
SUM(CASE WHEN T$YEAR=2006 THEN T$AUPP$1 ELSE 0 END) AS "2006 JAN",
SUM(CASE WHEN T$YEAR=2006 THEN T$AUPP$2 ELSE 0 END) AS "2006 FEB",
SUM(CASE WHEN T$YEAR=2006 THEN T$AUPP$3 ELSE 0 END) AS "2006 MARCH"
FROM baandb.ttdinv750700
GROUP BY T$ITEM

This select only few years and month. My problem is My Dates ranges from 2004 to today. And new months and years gets added. I need my script to be dynamic. Please Help. T$AUPP$1 to T$AUPP$12 is my months.

A problem well stated is a problem half solved.
-Charles F. Kettering


See More: Dynamic select Scripts / Pivot

Report •


#1
January 11, 2009 at 03:22:23
Use SubStrings to extract the Year and Month and the corresponding strings to make the Target String.

Report •
Related Solutions


Ask Question