Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Import CSV into DB2 table using column names to order data

Posted on 2005-04-06
Medium Priority
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
  • 2
LVL 46

Expert Comment

by:Kent Olsen
ID: 13720490

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

ID: 13721497
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

ghp7000 earned 500 total points
ID: 13721539
oops, sorry, should be

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

Author Comment

ID: 13734256
Thanks that works.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

580 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