Import CSV into DB2 table using column names to order data

Posted on 2005-04-06
Last Modified: 2008-01-09
I am able to import csv's into a db2 database using:

db2 connect to DB01user USERNAME using PASSWORD
db2 -tvf C:\files\create_tables.sql

However this ignores the column header and imports the data in the order in which it appears in the csv. Is there any way I can get the data to be imported according to the order of the column names in the first row?

The csv's are obtained from a number of sources which I don't have access to and so it would be very useful if I could make use of the column names to reorder the data to match my database.

Question by:servantis
    LVL 45

    Expert Comment


    I'm unaware of any practical way for DB2 import to use the names in the first row as the column names.

    Do you have Micro$oft Access?  It will read your CSV file and use the first row for column names.  You can also export the Access to DB2 which will give you the desired effect.


    LVL 13

    Expert Comment

    yes, you can load the data with method P
    assume you have a table with 4 columns, col1 , 2, 3  and 4
    your data file has 5 columns, but you want col1 in your data file to be loaded into column 4 of your table

    db2 load from myfile.del of del method P (4) replace (or insert) into mytable (column name)
    LVL 13

    Accepted Solution

    oops, sorry, should be

    db2 load from myfile.del of del method P (1) replace (or insert) into mytable (column 4 name)

    Author Comment

    Thanks that works.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
    Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now