Advertisement
deeejay

DB2 - Unpivot Data

Jul 27th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.66 KB | None | 0 0
  1. SELECT MCORP, MYEAR, MINUM, MDESC, MONTH, ACTUAL, BUDGET
  2.  FROM LIBRARY_NAME.FILENAME AS S,
  3.     LATERAL(VALUES ('JANUARY', S.MCAS01, S.MCBS01),
  4.                    ('FEBRUARY', S.MCAS02, S.MCBS02),
  5.                    ('MARCH', S.MCAS03, S.MCBS03),
  6.                    ('APRIL', S.MCAS04, S.MCBS04),
  7.                    ('MAY', S.MCAS05, S.MCBS05),
  8.                    ('JUNE', S.MCAS06, S.MCBS06),
  9.                    ('JULY', S.MCAS07, S.MCBS07),
  10.                    ('AUGUST', S.MCAS08, S.MCBS08),
  11.                    ('SEPTEMBER', S.MCAS09, S.MCBS09),
  12.                    ('OCTOBER', S.MCAS10, S.MCBS10),
  13.                    ('NOVEMBER', S.MCAS11, S.MCBS11),
  14.                    ('DECEMBER', S.MCAS12, S.MCBS12)            
  15.             ) AS T(MONTH, ACTUAL, BUDGET)
  16. WHERE MYEAR = 2016
  17. AND MINUM = 580
  18. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement