Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Summarize table
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01339319
Message ID:
01339332
Vues:
14
This message has been marked as a message which has helped to the initial question of the thread.
You can simplify your code a bit as below;
SELECT table1
SCAN
   SELECT tempCursor
   LOCATE FOR cLegend =  CMONTH(table1.date)
   IF NOT FOUND()
      APPEND BLANK
   ENDIF
   REPLACE Credit WITH Credit + table1.Credit, ;
                   cLegend WITH CMONTH(table1.date)
ENDSCAN
Here's the reasoning for the adjustments I have made. It is a bad idea to use the alias in a replace command as it can cause weird behavior if the incorrect alias is selected when the replace executes. By leaving the alis off of the field names you will get an error if the worng table is selected. Also you can replace more than one field in a single replace command. You don't need seperated replace statements as the append blank will create a record with the Credit field equal to zero so you can add the value from Table1 just like you do if the record in there. The append blank does not need the IN clause because Tempcursor is the current alias anyway.

There were a couple of typos in your sample code that if they exist in the actual code they would prevent things from working correctly. I have commented them in the code below.
SELECT table1
SCAN 
   SELECT tempCursor
   LOCATE FOR tempCursor.CLEGEND = CMONTH(table1.date)
   IF NOT FOUND() 
      APPEND BLANK IN tempCursor
      replace tempCursor.credit WITH table1.credit
      replace tempCursor.cLegend WITH CMONTH(table1.data) && Data should be Date
   ELSE
      REPLACE tempCursor.CREDIT WITH tempCursor.credit + table1.CREDIT
      replace tempCursor.cLegend WITH CMONTH(table.date)  && Table should be table1
   ENDIF
ENDSCAN
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform