list records in txt file

list records in txt file

Post by Heid » Tue, 01 Jul 2003 20:55:54


Hello,

I need to list records from one table in txt file which
are not in second table. How to do that?

Thanx,
Heidi
 
 
 

list records in txt file

Post by Cindy Wine » Tue, 01 Jul 2003 22:10:08

Hi Heidi,

There is more than one way to do this, and the way you choose will depend on
what happens to the data after you've selected it. You haven't said what
format the text file is in, and you haven't said whether you need to compare
the whole record or whether you can just select the new records based on a
primary key.

If I were doing this I'd create a cursor to receive the data and the APPEND
FROM the text file. Then I'd do an SQL select statement to
SELECT * FROM IncomingData ;
WHERE IncomingData.PrimaryKey NOT IN ;
(SELECT PrimaryKey FROM ExistingData

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
XXXX@XXXXX.COM , www.cindywinegarden.com

 
 
 

list records in txt file

Post by Heid » Tue, 01 Jul 2003 22:27:16

I have two tables (dbf), for example, Table 1 and Table 2.
I have primary key, so that I can find matching records.
I am creating .txt file where I have to place those
records from Table 1 which are not in Table 2.


choose will depend on
haven't said what
you need to compare
records based on a
data and the APPEND
 
 
 

list records in txt file

Post by Georg » Tue, 01 Jul 2003 22:41:42

Oops, Copy To produces a dbf file, try instead:
LIST TO C:\myFileName.txt


One of many ways would be:

Select * From Table1 Where primaryKey Not In (Select primaryKey From Table2)
Copy To 'C:\myFileName.TXT'
 
 
 

list records in txt file

Post by Cindy Wine » Wed, 02 Jul 2003 04:42:19

You can use:

Copy To 'C:\myFileName.TXT' DELIMITED
or
Copy To 'C:\myFileName.TXT' TYPE SDF

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
XXXX@XXXXX.COM , www.cindywinegarden.com



Oops, Copy To produces a dbf file, try instead:
LIST TO C:\myFileName.txt



One of many ways would be:

Select * From Table1 Where primaryKey Not In (Select primaryKey From Table2)
Copy To 'C:\myFileName.TXT'
 
 
 

list records in txt file

Post by Heid » Wed, 02 Jul 2003 18:19:54

I don't have problems in listing but how to list exactly
those records which are not in Table2.
For listing I use functions fcreate() and fopen() (if file
exists) and then open it with MODIFY FILE myfile.txt NOWAIT
 
 
 

list records in txt file

Post by Cindy Wine » Wed, 02 Jul 2003 23:10:46

One way is to import the table into a cursor. Use SQL Select to find the
records that aren't in Table1. Use COPY TO to create a new text file.

Another way is to read your text file line-by-line. SEEK or LOCATE the
primary key from the text file record in Table1. If it's not found, write
the text file record to the new file.

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
XXXX@XXXXX.COM , www.cindywinegarden.com