Question : Take some of the data from cursor to a variable

So am I over thinking this one? LOL

I have a cursor and and have some data in it. I want that data to go to a table for that date so I can keep trake of every date and location.

I have seen some code in the past that scans the cursor and selects certain fields and store to memory as a variable then used to REPLACE in a table.

Can't I just use INSERT INTO myTable?
but I also need to make sure that the date and location are not already there or if it is then REPLACE?

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
select myTable
locate for date=ldDate and loc=lnLoc
if !found()
  insert into myTable (date,loc,total,avg)
     values(ldDate,lnLoc,lnTotal,lnAvg)
else
replace date with ldDate
replace loc with lnLoc
replace total with lnTotal
replace avg with lnAvg

endif

Answer : Take some of the data from cursor to a variable

A little bit better solution is just one REPLACE command which does not contain key fields because they have correct value already. One REPLACE also locks the record just once which also saves some time.

Also the table myTable should have index on date field and also on loc field to allow Rushmore optimization if the number of records is greater than let say 1000.
1:
2:
3:
4:
5:
6:
7:
8:
9:
select myTable 
locate for date=ldDate and loc=lnLoc 
if !found() 
  insert into myTable (date,loc,total,avg) 
     values(ldDate,lnLoc,lnTotal,lnAvg) 
else 
  replace total with lnTotal, ;
            avg with lnAvg 
endif
Random Solutions  
 
programming4us programming4us