Information générale
Catégorie:
Codage, syntaxe et commandes
Titre:
Replacing records in table
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
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement