Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Are There Any Simple For This?
Message
De
18/07/2001 07:44:27
 
 
À
18/07/2001 06:57:18
Jimi Lee
Pop Electronic Products Ltd.
Hong Kong, Hong Kong
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00531899
Message ID:
00531909
Vues:
16
>Hello everyone,
>
>I have many small tables with different names but identical structure, my task is to extract some data from each of them and append into a cursor. The only way I can do this is to save the data from small tables into an array, then put them into the cursor, but I feel this not the best way, I want to transfer the data directly but not through the array.
>
>The way I want to do is:
>
>Create Cursor MyCursor
>FileList=adir(SmallTable_xx.dbf)
>
>For each SmallTable in FileList
>  Extract useful data from SmallTable
>  Insert the data into the Cursor &&such that no need to sort afterward
>Endfor
>
>
>
>Is it possible to open 2 tables at the same time, then put the data from one to another? If yes, would someone please teach me how? Or any other suggestions?
>
>Thanks in advance!!

Hi Jimi,

You are probably going to have to use one array and then do an INSERT since VFP's INSERT SQL command does not do a 'INSERT INTO tablename (SELECT * from AnotherTableName)'

Of course you can open 2 tables or more at the same time. Use SQL statements in your loop thus;
Create Cursor MyCursor (yourfieldname1 type precision, ...)
ADIR(FileList, 'SmallTable_*.dbf')

*-- ALEN() will give you the row count of the array fileList
For x=1 to ALEN(FileList,1) 
*-- Open the table in an unused work area
  USE FileList[x,1] IN 0

*-- Extract your data
  SELECT yourFields 
  FROM (FileList[x,1])
  WHERE yourSelectCondition
  INTO ARRAY dataArray

*-- Insert the data into the Cursor 
  INSERT INTO DBF('MyCursor') FROM ARRAY dataArray

*-- Close files and clean up
  USE IN (FileList[x,1])
  RELEASE dataArray
Endfor
Regarding the sort order, you could sort MyCursor after all inserts are finished. You will not be able to sort while inserts are going on since you cannot 'insert before' a record.

Cheers
Sanjay Kapoor

Relatively speaking is a conversation with Einstein
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform