Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need help with UPDATE
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00554995
Message ID:
00555092
Vues:
16
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--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform