Sunday, 15 June 2014

Python pymssql how do I insert in a for loop? -



Python pymssql how do I insert in a for loop? -

how insert table results query? code loops through query , results assigned variables. insert row code terminates though there still more rows in result set. proper way have code go on , insert rows result set?

class="snippet-code-html lang-html prettyprint-override">cur.execute (query3) row in cur: calldate= row['calldate'] account= row['account'] call_time= row['call_time'] distributor_name= row['distributor_name'] callerid= row['callerid'] call_status= row['call_status'] partner_revenue= row['partner_revenue'] tracking_phone= row['tracking_phone'] quality_string= row['quality_string'] column9= row['column 9'] column10= row['column 10'] column11= row['column 11'] column12= row['column 12'] if column9 none , column10 none , column11 none , column12 none: to_db = calldate, account, call_time, distributor_name,callerid, call_status, partner_revenue, tracking_phone, quality_string if column9 not none , column10 none , column11 none , column12 none: to_db = calldate, account, call_time, distributor_name,callerid, call_status, partner_revenue, tracking_phone, quality_string +", "+ column9 if column9 not none , column10 not none , column11 none , column12 none: to_db = calldate, account, call_time, distributor_name,callerid, call_status, partner_revenue, tracking_phone, quality_string +", "+ column9 +", "+ column10 if column9 not none , column10 not none , column11 not none , column12 none: to_db = calldate, account, call_time, distributor_name,callerid, call_status, partner_revenue, tracking_phone, quality_string +", "+ column9 +", "+ column10 +", "+ column11 if column9 not none , column10 not none , column11 not none , column12 not none: to_db = calldate, account, call_time, distributor_name,callerid, call_status, partner_revenue, tracking_phone, quality_string +", "+ column9 +", "+ column10 +", "+ column11 +", "+ column12 cur.execute (ins_query,(to_db)) conn.commit()

for row in cur: #... cur.execute (ins_query,(to_db))

you're performing operation (execute) on object you're iterating on (cur), find way around , problem should gone!

python pymssql

No comments:

Post a Comment