Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Replacing records in table
Message
De
20/07/2000 18:02:15
 
 
À
20/07/2000 17:50:01
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00395142
Message ID:
00395147
Vues:
11
INSERT INTO (INSERT - SQL in help) always appends a new record. Look at UDATE - SQL or REPLACE instead.

hope this helps,
Bridget

>I have a table called packslip that has 12 records in it with a studentid and courseid. I have a temporary cursor cpack. If the table has the studentid and courseid that are in the cursor I want to replace those records in the table with the ones in the cursor. The problem is I get new records not changed ones. The reason I have the scan in here is to associate the quantity with the material.
>
>The first time I just want to insert the records from the cursor if the student and courseid aren't in the table together. If they are I want to replace them with the current data in the cursor.
>
>Here is my code. What am I doing wrong and how do I replace the records not create new ones for a student that is in that course?
>
>select packslip
>locate for packslip.studentid = cpack.studentid and packslip.courseid = cpack.courseid
>if !found()
> select cpack
> scan
> quant = iif(inlist(materialid,"VX29","VX39"), qty3, iif(inlist(materialid, "VX57","VX50"),qty2,iif(inlist(materialid, "VX51"),qty,iif(inlist(materialid,"CJ30","CJ31","CJ32","CJ33","CJ34","CJ35","CJ36","CJ37","CJ38","CJ39","CJ40"), "2","1"))))
>
>insert into packslip(studentid, courseid, materialid, descript,qty) values (cpack.studentid,cpack.courseid,;
> cpack.materialid, cpack.description, quant)
> endscan
>else
> select cpack
> scan
> quant = iif(inlist(materialid,"VX29","VX39"), qty3, iif(inlist(materialid, "VX57","VX50"),qty2,iif(inlist(materialid, "VX51"),qty,iif(inlist(materialid,"CJ30","CJ31","CJ32","CJ33","CJ34","CJ35","CJ36","CJ37","CJ38","CJ39","CJ40"), "2","1"))))
>
> replace studentid with cpack.studentid, courseid with cpack.courseid,;
> materialid with cpack.materialid, descript with cpack.description,;
> qty with quant for packslip.studentid = cpack.studentid and packslip.courseid = cpack.courseid in packslip
> endscan
>endif
>Thanks,
>Tyler
Bridget K. Dawes
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform