Using a list


vsql = "SELECT client_id FROM client"

cn.execute(vsql)

rs = cn.resultset

clst = rs.ToString()


'==update Client with total hours and hourly charges

dim vttl_amt as n

dim vttl_hrs as n

for each foo in clst

       vsql = "SELECT SUM(t1.hours_tobill * t2.rate) as ttl_amt,SUM(t1.hours_tobill) as ttl_hrs FROM billing_trans t1,billing_project t2 WHERE t1.type_id='HRS' AND no_charge<>1 AND t1.project_id = t2.id AND t1.client_id="+foo

       cn.execute(vsql)

       rs = cn.ResultSet

       vttl_amt = rs.data("ttl_amt")

       vttl_hrs = rs.data("ttl_hrs")

       vsql = "UPDATE client SET c_cur_hrs_charges={vttl_amt},c_cur_hours={vttl_hrs} WHERE client_id={foo}"

       vsql = evaluate_string(vsql)

       if cn.execute(vsql) = .f.

               lst3 = lst3 + cn.callresult.text + crlf()

       end if

next



Looping through records

Using a list to loop through records


cn = sql::Connection

rs = sql::ResultSet

args = sql::Arguments

vsql = "SELECT client_id FROM client"

cn.execute(vsql)

rs = cn.resultset

clst = rs.ToString()


'==update Client with total hours and hourly charges

dim vttl_amt as n

dim vttl_hrs as n

for each foo in clst

       vsql = "SELECT * FROM billing WHERE type_id='HRS'

       cn.execute(vsql)

       rs = cn.ResultSet

       vttl_amt = rs.data("ttl_amt")

       vttl_hrs = rs.data("ttl_hrs")

       vsql = "UPDATE client SET c_cur_hrs_charges={vttl_amt},c_cur_hours={vttl_hrs} WHERE client_id={foo}"

       vsql = evaluate_string(vsql)

       if cn.execute(vsql) = .f.

               lst3 = lst3 + cn.callresult.text + crlf()

       end if

next