How can I Import data from one text file to multiple tables?

G

Guest

I have the data of 3 tables in one text file, please tell me how can i import
the data to three different tables.
The records in the text file are in this order,
1st record of 1st file, 1st record of second file, 1st record of third
file.......

thanks
Dash
 
J

John Nurick

If this is a one-off task, I'd use text file tools to split the file
into three simple files, one for each table, that can be imported in the
usual way. Assuming that the input file is laid out like this:

Table1 Record1
Table2 Record1
Table3 Record1
Table1 Record2
Table2 Record2
Table2 Record2
...

I'd use Perl from the Windows command prompt, substituting the actual
names and paths of the files you want.

perl -ne"print if ($. % 3) == 1" INPUT.txt > TABLE1.txt
perl -ne"print if ($. % 3) == 2" INPUT.txt > TABLE2.txt
perl -ne"print if ($. % 3) == 0" INPUT.txt > TABLE3.txt

Perl uses $. for the line number of the input, so
$. % 3
is "line number modulo 3", which cycles 1,2,0,1,2,0 from the first line
on. If Perl isn't installed on your computer you can download it free
from www.activestate.com

It's possible to write code to do the same thing in just about any other
programming or scripting language. If this import was going to be a
regular task, I'd do it differently, writing Access VBA code that opens
three recordsets, one for each table, and then reads the file a line at
a time. The first line would be parsed and appended to the first table,
then the second and third to their tables, and then back to line 4 and
the first table again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top