Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a Table from certain Fields in another Table

Status
Not open for further replies.

bebbo

Programmer
Dec 5, 2000
621
GB
I'm creating a file similar to my Stock file as below. The stock file has lots more fields. Is there an easier way I can create "STOCKCHK.DBF" with the fields from Stock and extra fields as below. Also I would like any data in the appropriate fields in Stock to be in STOCKCHK when this file is created.

At the moment I create the file as below then check contents in the Stock File and put it into STOCKCHK. This does become a nusiance sometimes and I was wondwerinf if there was an easier way to do it. Similar to making an array from a table with only cetain fields. Thanks.

IF !FILE(LOCALDIR + "\STOCKCHK\STOCKCHK.DBF")
SELECT STOCK
COPY STRUCTURE TO (LOCALDIR + "\STOCKCHK\STOCKCHK.DBF");
FIELDS PLU, DESCR, DEPT, QUANTITY
SELECT 0
USE (LOCALDIR + "\STOCKCHK\STOCKCHK") EXCLUSIVE
ALTER TABLE STOCKCHK ADD CHKDATE D(8)
ALTER TABLE STOCKCHK ADD CHKTIME N(4)
ALTER TABLE STOCKCHK ADD NEWQUANT N(10,1)
INDEX ON PLU TAG PLU
INDEX ON DESCR TAG DESCR
ENDIF
 
interesting enough there is the ability to redimension an active array in foxpro that might solve your event.

here is the afields used to pump the fields into the array that later you will use to create your table.

In this case this is a table with 10 fields so the array created below is dimensioned to arryNew(10,16)

=AFIELDS(arryNew,'products')


now redimension it to add the new fields you want and change the values of the array as below:

DIMENSION arryNew (11,16)
arryNew(11,1) = 'NewName'
arryNew(11,2) = 'C'
arryNew(11,3) = '25'
arryNew(11,4) = 0
arryNew(11,5) = .f.
arryNew(11,6) = .f.
for i = 7 to 16
arryNew(11,i) = ''
endfor
now create the new table from the array

CREATE TABLE newStock FROM ARRAY arryNew
Dancing is easy. Now dancing on a floating raft in the middle of an October storm in the middle of the North Atlantic, that is hard.
 
bebbo;

What about something like this...

SELECT PLU, DESCR, DEPT, QUANTITY, ;
{} AS cjkdate, ;
0000 AS chktime,;
00000000.0 AS newquant ;
FROM stock;
INTO TABLE STOCKCHK
*
* do the index stuff

Regards - Wayne
 
HI

nChkTime = 0000
nNewQty = 0000000000.0
IF !FILE(LOCALDIR + "\STOCKCHK\STOCKCHK.DBF")
cFile = LOCALDIR + "\STOCKCHK\STOCKCHK.DBF"
SELECT PLU, DESCR, DEPT, QUANTITY, ;
{} AS CHKDATE, nChkTime AS chktime, ;
nNewQty AS NewQty ;
FROM stock INTO DBF (cFile)
INDEX ON PLU TAG PLU
INDEX ON DESCR TAG DESCR
ENDIF

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top