Search code examples
sqlibm-midrangedb2-400

IBM i UNION *ALL used here


I have this in CL and would like to make it into a view. I first run 2 queries which are creating these 2 tables. How would the code here for the UNION ALL be? the 2 tables are (Logical) views

CPYF       FROMFILE(JETDTA/EODDETAILH) +                 
              TOFILE(JETDTA/EODDETAILS) MBROPT(*ADD) +    
              FMTOPT(*NOCHK)                                
              MONMSG CPF0000              

Solution

  • Besides the structure of the queries result must match, you can do it with:

    CREATE VIEW yourViewName AS 
    SELECT *
    FROM JETDTA.EODDETAILH
    UNION
    SELECT *
    FROM JETDTA.EODDETAILS
    

    You can find more information about the CREATE VIEW command here and about the UNION clause here, both of those are part of SQL/400.