• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • First Normal Form On The Fly

    July 10, 2013 Ted Holt

    Converting normalized data into a repeating group is a common requirement, and we have discussed that topic several times in Four Hundred Guru, even in this issue. Sometimes the need arises to convert data in the other direction, i.e., to convert a repeating group to a normalized form. This is a handy technique to know, and it’s easy.

    Suppose you’ve been given a spreadsheet with 13 columns of data. The first column is an item number. The next 12 columns are replacement costs for each month. You’ve been asked to load the data into a normalized table (physical file) of three columns (fields):

    1. Item number
    2. Month
    3. Cost

    That is, you need to convert this:




    Item

    Item

    January

    February

    . . .

    December

    A

    5.41

    5.41

    . . .

    6.18

    B

    3.80

    4.50

    . . .

    12.55

    into this:




    Item

    Item

    Month

    Cost

    A

    2012-01-01

    5.41

    A

    2012-02-01

    5.41

    . . .

     

     

    A

    2012-12-01

    6.18

    B

    2012-01-01

    3.80

    B

    2012-02-01

    4.50

    . . .

     

     

    B

    2012-12-01

    12.55

    To convert columns to rows, use UNION ALL.

    Assuming you’ve copied the spreadsheet data into a table called ITEMCOSTS and will load table COSTHIST, here’s the SQL you need.

    insert into costhist
    
       select c.ItemNumber, '2012-01-01', c.cost01
         from itemcosts as c
       union all
       select c.ItemNumber, '2012-02-01', c.cost02
         from itemcosts as c
       union all
    
    ( . . . etc. for months 3 - 11 . . .)
    
       union all
       select c.ItemNumber, '2012-12-01', c.cost12
         from itemcosts as c
       order by 1,2
    

    The expression requires a SELECT for each “bucket”. In this case, there are 12 select statements because there are 12 months.

    UNION would produce the same result as UNION ALL, but UNION ALL performs much better because it does not check for duplicate rows.

    I would hate to use this technique with the file that FHG reader David told me about recently. It has six repeating fields, each one of which has 90 buckets. (Yes, 90!) But I suppose it could be done.

    RELATED STORY

    Presenting Vertical Data Horizontally



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Linoma Software:  FREE Webinar: Conquer Compliance Requirements. July 18.
    Cybernetics:  Ditch the tape backup? Up to 4.3 TB/hr! Start saving now!
    Abacus Solutions:  Qualified IBM i users eligible for free pair of running shoes

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ The Reg: More News From ITJ EIC Timothy Prickett Morgan

    Enterprise App Store Approach to Spread for Mobile Apps, Study Says What Is IBM Going To Do With Its Systems Business?

    Leave a Reply Cancel reply

Volume 13, Number 13 -- July 10, 2013
THIS ISSUE SPONSORED BY:

WorksRight Software
PowerTech
American Top Tools

Table of Contents

  • Presenting Vertical Data Horizontally
  • First Normal Form On The Fly
  • Admin Alert: Major And Minor IBM i Power System Upgrades

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle