0

I am trying to use python to use a parametrized query through a list. This is the following code:

loan_records =['604150062','604150063','604150064','604150065','604150066','604150067','604150069','604150070']

borr_query = "select distinct a.nbr_aus, cast(a.nbr_trans_aus as varchar(50)) nbr_trans_aus, c.amt_finl_item, case when a.cd_idx in (-9999, 0) then null  else a.cd_idx end as cd_idx, a.rate_curr_int, case when a.rate_gr_mrtg_mrgn = 0 then null else a.rate_gr_mrtg_mrgn end as rate_gr_mrtg_mrgn, a.rate_loln_max_cap, case when a.rate_perdc_cap = 0 then null else a.rate_perdc_cap end as rate_perdc_cap from db2mant.i_lp_trans a  left join db2mant.i_lp_trans_borr b on a.nbr_aus = b.nbr_aus and a.nbr_trans_aus = b.nbr_trans_aus left join db2mant.i_lp_finl_item c on a.nbr_aus = c.nbr_aus and a.nbr_trans_aus = c.nbr_trans_aus where a.nbr_trans_aus in (?) and c.cd_finl_item = 189"

ODS.execute(borr_query, loan_records)
        #PML.execute(PML_SUBMN_Query, (first_evnt, last_evnt, x))
    
ODS_records = ODS.fetchall()
ODS_records = pd.DataFrame(ODS_records, columns=['nbr_aus', 'nbr_trans_aus', 'amt_finl_item', 'cd_idx', 'rate_curr_int', 'rate_gr_mrtg_mrgn', 'rate_loln_max_cap', 'rate_perdc_cap'])

When I try to run this code: this is the following error message: error message

Richard
  • 1
  • 1
  • Try casting loan_records to a tuple first. – JonSG Feb 13 '23 at 19:58
  • Does this answer your question? [imploding a list for use in a python MySQLDB IN clause](https://stackoverflow.com/questions/589284/imploding-a-list-for-use-in-a-python-mysqldb-in-clause) and/or https://stackoverflow.com/questions/283645/python-list-in-sql-query-as-parameter – JonSG Feb 13 '23 at 19:59
  • Tried to do that, loan_records = ('604150062','604150063','604150064','604150065','604150066','604150067','604150069','604150070'), transformed it into a tuple, still same error message. – Richard Feb 13 '23 at 20:57

0 Answers0