DB2 Code (Pivot Table)

DB2 Code (Pivot Table)

 

  

John,
The answer to your question (how can you take the following code and data from a horizontal output to a vertical output - converting rows to a column) is listed below. Have a great Day! hehe.


SELECT DISTINCT DEPTNO, DEPTNO, DEPTNO, DEPTNO, DEPTNO
FROM DEDBADM.EMP

-----------------------------------------
OUTPUT
-----------------------------------------

DEPTNO DEPTNO1 DEPTNO2 DEPTNO3 DEPTNO4
----------- ----------- ----------- ----------- -----------
10 10 10 10 10
20 20 20 20 20
30 30 30 30 30



--------------------------------------------
DESIRED OUTPUT
--------------------------------------------

DEPTNO
-----------
10
10
10
10
10
20
20
20
20
20
30
30
30
30


HERE IT IS! hehe.

-----------------------------------------
CODE
-----------------------------------------
SELECT DISTINCT DEPTNO
FROM DEDBADM.EMP2
UNION ALL
SELECT DISTINCT DEPTNO
FROM DEDBADM.EMP2
UNION ALL
SELECT DISTINCT DEPTNO
FROM DEDBADM.EMP2
UNION ALL
SELECT DISTINCT DEPTNO
FROM DEDBADM.EMP2
UNION ALL
SELECT DISTINCT DEPTNO
FROM DEDBADM.EMP2
ORDER BY DEPTNO;

--------------------------------------------
OUTPUT
--------------------------------------------

DEPTNO
-----------
10
10
10
10
10
20
20
20
20
20
30
30
30
30



---------------------------------------------------------------------
PLEASE CLICK REPLY-ALL TO SEND A REPLY TO EVERYONE
website: http://www.LazyDBA.com
To unsubscribe: http://www.lazydba.com/unsubscribe.html


Please take a few minutes to provide feedback on the quality of service you received. The Department of Education values your feedback as a customer. Commissioner John L. Winn is committed to continuously assessing and improving the level and quality of services provided to you by Department staff. Simply use the link below. Thank you in advance for completing the survey.


http://data.fldoe.org/cs/default.cfm?staff=Ed.[Email address protected]

DB2 & UDB email list listserv db2-l LazyDBA home page