Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need help with UPDATE
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00554995
Message ID:
00555092
Views:
17
It's not going to work because only stockB.qty from the first record with corresponded barcode will be added to stockA.qty . Here's fixed version
USE stockB
SELECT barcode, SUM(qty) AS qty ;
  FROM StockB ;
  GROUP BY 1 ;
  INTO CURSOR StockTemp

INDEX ON barcode TAG barcode
SET ORDER TO barcode

USE stockA in 0
SELECT stockA
SET RELATION TO barcode INTO StockTemp

REPLACE ALL qty WITH stockA.qty + StockTemp.qty IN stockA
Here's another way
Dimension laQty[1]
USE stockA in 0
SELECT stockA
Scan
	laQty[1] = 0
	SELECT SUM(qty) AS qty ;
		  FROM StockB ;
		  WHERE StockB.barcode = StockA.barcode ;
		  INTO ARRAY laQty
	REPLACE StockA.qty WITH stockA.qty + laQty[1]
ENDSCAN	
AFAIK, You cannot do this using SQL Update because in VFP it doesn't support neither join condition in where clause nor query in the SET clause.


>>UPDATE stocka set stocka.qty = stocka.qty + (select qty from stockx where
>>barcode = stocka.barcode).
>
>Untested code to get you going:
>
>USE stockB
>SET ORDER TO barcode
>
>USE stockA in 0
>SELECT stockA
>SET RELATION TO barcode INTO stockB
>
>REPLACE ALL qty WITH stockA.qty + stockB.qty IN stockA
>
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform