servantis
asked on
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.
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.
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)
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)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks that works.
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