views:

48

answers:

1

Hallo all,

I have two files, one called "part1.txt" and another one called "part2.txt", which look like following

part1.txt           part2.txt
lili                like eating apple
lucy                like playing football

Now i want to insert the contents of these two files into a single table with the schema

table_name(linefrompart1 varchar(100), linefrompart2 varchar(50))

My program reads the first file line by line and insert the data into the first column. But if it reads the second file and tries to insert the data line by line into the second column, it doesn't work the way i want. A table which i want should look like following

linefrompart1   linefrompart2
  lili            like eating apple
  lucy            like playing football

But instead i got the following table

  linefrompart1   linefrompart2
  lili            null
  lucy            null
  null            like eating apple
  null            like playing football

Does somebody know how i can fix this problem? Thank you!!

+1  A: 

You should read both files simultaneously line-by-line and insert the data into the table with a single insert per line.

INSERT INTO table_name (linefrompart1, linefrompart2)
VALUES ('lili', 'like eating apple')

Alternatively if this is not possible then you could add an extra column to your table to store the line number and use an update statement with 'WHERE linenumber = x'.

Mark Byers
Hallo Mark. I took the alternative solution and it works well. Thank you very much!
TianDong
You are welcome!
Mark Byers