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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating multiple records

Status
Not open for further replies.

prakashroch

Technical User
May 2, 2002
21
0
0
US
i have two tables one is try3 and other try4

Field try3 ->Itemname,Sales,Itemid
in try3 Itemname and itemid colums are are alredy filled and sales for each record is "Zero" ,there are 100 such records

Field try4 ->Sales,Itemid
Each distinct itemid has sales value

i want to assign itemid from table try4 to records in try3

can it be done in single SQl statemnt or do i have to use loop to read each itemid???

Thanks
 
TRY THIS

SELECT TRY4
GO TOP
SCAN FOR (YOUR CRITERIA)
&&SET YOUR VARIABLES HERE
REPLACE TRY3.FIELD(S) WITH (YOUR VARIABLES)FOR TRY3.FIELD=(YOUR CRITERIA)
ENDSCAN

FOXPRO WILL SCAN THE TABLE AND EXECUTE THE CODE FOR EACH RECORD THAT MEETS YOUR SEARCH CRITERIA.


 
First of all, I should not use column Sales in table try3, it is redundant. The only reason to do this from my point of view is performance.

But OK, if you want column Sales, this would be the SQL statement:

update try3 t3
set t3.sales = select t4.sales from try4 t4 where t3.itemid=t4.itemid

Note: itemid should be unique!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top