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!

Inserting a field . . . but how

Status
Not open for further replies.

ShyFox

Programmer
Mar 22, 2003
210
ES
Hy,
Back again with a new question.
Have to tables. In table 1 I have a Code field and a TotQuant field. In table 2 I have the Code field and TodayQuant. Now I would like to bring the TodayQuant in table 1, but I want TodayQuant with the Code 1298 from table1 to be inserted exactly at the Code 1298 in table2. I would apreciate every sugestion.
Regards
 
ShyFox,
many ways...add logical field YTOT into today table
to indicate already summed today record.
use table1 as tot
index on code tag code
sele 2
use table2 as today
set rela to code into tot
scan for !ytot
if eof(tot)
inse into table1(tot.code) values(today.code)
endif
repl tot.totquant with tot.totquant + today.todayquant
repl today.ytot with .T. && indicate summed record
endscan
(not tested)
Tesar
 
Select table1
locate for table1.code = 1298
replace table2.todayquant with table1.TotQuant for table2.code = 1298 in "table2"
Slighthaze = NULL
 
slighthaze (IS/IT--Manageme)

You kill me ! This action must be done every day (automized in a button click) and we're talking here about 2 000 lines of code.

tesar (Programmer)
I will check your code now.

Thank you all.
Regards
 
Hi ShyFox,

1. If you want to add the field todat qty in Table1, you can add the field in that table for one time. That is a pretty easy job. (adding just the field).

2. Now to get the quantity from table2 to table1 for all the records..

** Index Table 2 on the code field (one time
and the index updates itself if it is a CDX index type)

USE TABLE2 ORDER codeField IN 1 ALIAS table2
USE TABLE1 IN 2 ALIAS table1
SELECT Table1
SET RELATION TO codeField INTO table2
REPLACE ALL todayqty WITH table2.todayQty

The code can be copied in a PRG and run every day.
:)
ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Hi ShyFox,

I wondered if you wanted to add a new field to Table1 or to increase the value of Table1.TotQuant?

If it was to increase the value of TotQuant,then you can do something like the following (for which you need an index tag for the Code field):

USE Table1
USE Table2 IN 0 ORDER Code && if you have this indexed
SET RELATION TO Code INTO Table2
REPLACE ALL TotQuant WITH TotQuant+Table2.TodayQuant

Stewart
 
Hi , assuming you are upating table 1 and 2 independantly, and the code field is unique in both tables...

select table1.*, table2.todayqty inner join on table2.code ==table1.code into table table3

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top