Import CSV into DB2 table using column names to order data

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.

servantisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenData Warehouse Architect / DBACommented:

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.


Kent

0
ghp7000Commented:
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)
0
ghp7000Commented:
oops, sorry, should be

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
servantisAuthor Commented:
Thanks that works.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB2

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.