I've been having trouble with 1 particular query for the past week. I can't find anything online for this specific situation (or atleast I'm not searching the right thing) but surely this is something somebody has done before. I'm generating a new table on each cycle (with an incrementing ID/key column, and 3 columns for my data) so the table name changes, then putting in some data (all integers). The line causing the error is:
cursor.execute(''' INSERT INTO ? (column1, column2, column3) VALUES (?, ?, ?) ''' , tablename, rowData[0], rowData[1], rowData[2])
The error I'm getting is:
('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the table variable "@P1". (1087) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)')
I previously tried using the usual python string formatting, with a dictionary
'''INSERT INTO %(table)s VALUES %(list0)i, %(list1)i, %(list2)i ''' % {"table":tablename, "list0":list[0], "list1":list[1], "list2":list[2]})
and some variations of the 2 formats but those have resulted in errors too.
Any help would be appreciated.