简体   繁体   中英

Split a Foxpro table into many other tables

I hope someone can help, I have been banging my head on this one.

I have two tables. One holds global address data and one holds country names.

I want to create separate tables for each country based on the country name - so for instance I want to look at the country name table, take the first country name and then scan the address table, select the correct records and then save them to an individual table with the name of the country as the file name, right the way through the country name file. eg

australia.dbf;
belgium.dbf etc.

I know it involves using a cursor and a SCAN but can't get my head around the syntax.

Thanks

This should get you what you need. I also have it make a sub-folder from whereever you are running this from for "PerCountry", so each individual country will be put in that folder. You can obviously move from there after-the-fact.

MD "PerCountry"

SELECT distinct country;
   FROM globalAddresses;
   INTO CURSOR C_JustCountry READWRITE 

SELECT C_JustCountry
SCAN 
   */ If a country has ANY spaces, change them to underscores
   cCurrentCountry = C_JustCountry.Country
   cNewOutputFile = "PerCountry\" + CHRTRAN( ALLTRIM(C_JustCountry.Country), " ", "_" )

   SELECT * ;
      from globalAddresses ;
      where country = cCurrentCountry ;
      INTO TABLE &cNewOutputFile
ENDSCAN

CLOSE TABLES all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM