* It's beter to store data location path into a variable ot * Application object propery. * This way it would be easy to change data locatino in the future, if neccessary lcDataPath = "c:\dsm\" USE (lcDataPath + "currentbalance") IN 0 USE (lcDataPath + "redeem") IN 0 USE (lcDataPath + "date") IN 0 MS039=SQLCONNECT("ms039as01") IF MS039 < 0 * Use AERROR to get details about ODBC error and process it ENDIF * Textmerge makes code more readable TEXT TO lcSql TEXTMERGE NOSHOW PRETEXT 7 select item, LTRIM(customer)as customer, points, agreement_number from iaagmaster where agreement_number in ('45493', '45492') order by customer ENDTEXT lnResult = SQLEXEC(MS039, lcSql, "AG") IF lnResult < 0 * Use AERROR to get details about ODBC error and process it ENDIF SQLDISCONNECT(MS039) * There's a problem with followinf select * because there're no JOIN condition between 'redeem' and 'redeem ' tables * As result it creates Cross-join SELECT customer, sum(redeem) as redeemed ; FROM redeem , date ; WHERE date between startdate AND enddate; group BY customer; into CURSOR redemption SELECT customer, points) as points FROM ag INTO cursor Pts SELECT customer, SUM(VAL(points)) as points ; FROM ag ; GROUP BY customer ; INTO CURSOR CurtPts SELECT NVL(red.customer, NVL(cbal.customer,cpts.customer)) AS customer, ; NVL(cbal.balance,0) - NVL(red.redeemed,0) + NVL(cpts.points,0) as balance ; FROM redemption red ; FULL JOIN currentbalance cbal ON red.customer=cbal.customer ; FULL JOIN CurtPts cpts ON cpts.customer=red.customer ; into CURSOR end * Assuming that currentbalance table has index on customer SELECT end * Update balance if cutomer exists and inser new record if it doesn't SCAN IF SEEK(end.customer, "currentbalance", "customer") REPLACE balance WITH end.balance IN currentbalance ELSE INSERT INTO currentbalance ("customer", "balance") ; VALUES (end.customer, end.balance) ENDIF ENDSCAN USE IN ag USE IN CurtPts USE IN end USE IN currentbalance USE IN redeem USE IN date>I agree. Here is my exact code I made some changes and decided to replace the table(currentbalance). Redeem is a table I use to add customers as well as add any redemeptions a customer has redeemed in the last month. If you see any short comings to this approach or any better ideas I'm game. THanks.