General information
Category:
Coding, syntax & commands
Tyler,
Your code looks exactly right -
IF NOT FOUND - SCAN, INSERT new record,
IF FOUND - SCAN, Replace values in existing record.
You say the problem is that you are expecting to get REPLACEd records and you are getting INSERTed records.
Have you tried setting up some test data - little tables of just a couple of records so you know exactly what should happen at each step of the way, and following the data with the debugger?
Are you perhaps being bitten by SET("EXACT") when comparing the StudentId and CourseId?
>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
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only