Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FreeTDS SQL Server Invalid data type

I am using Ubuntu. I want to access Microsoft sql database using pyodbc in django. I installed all requirements. To do that, I wrote this

cursor.execute('SELECT Id FROM %s' %table_name) 

I am getting error which is

[HY004] [FreeTDS][SQL Server]Invalid data type (0) (SQLBindParameter)')

But, when I try this

cursor.execute('SELECT * FROM mytable')

It works fine. Why do I see that error, Is there a way to solve that issue ?

like image 216
John Smith Avatar asked May 06 '26 01:05

John Smith


1 Answers

SQL Server doesn't support variables for table names. Try building the whole statement as a string and then executing it.

like image 77
scutch Avatar answered May 08 '26 15:05

scutch