I have a problem with running an SQL script in pandas with WHERE
in clause which is picking members of a list or tuple
tuple=(1,2,3,4,5,6, 7) # there are 2228 members
date=20200101
sql=pd.read_sql_query("""SELECT *
FROM [MY_TABLE] with (nolock)
WHERE [cod] IN (?)
and bi_partition>=?""", conn, params=[tuple, date])
The error returned:
('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]The data types varchar and ntext are incompatible in the equal to operator. (402) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)')
When using params =[str(tuple), str(date)] the error is:
('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]The data types varchar and ntext are incompatible in the equal to operator. (402) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)')
I have tried to fix it with different solutions I found on StackOverflow but it doesn't work.
Anybody can help?
Thank you