MS SQL Invalid Object Name

11.6k views Asked by At

I have

cursor.execute("select RM_ID FROM Sales.dbo.MARKETING where VERSION = 'SomeVersion'")

which gives me the traceback error:

pyodbc.ProgrammingError: ('42S02', "[42S02] [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'Sales.dbo.MARKETING'. (208) (SQLExecDirectW)")

I have several other lines of code:

cursor.execute("select RUNDATEEST FROM Sales.dbo.MARKETING where VERSION = 'SomeVersion'")

that are exactly the same except for the column name that give me no error. I'm not sure what my mistake is.

Of note:

  • I have already checked the table for the column name to make sure it exists.
  • I have noticed that this column is the key for this table. Perhaps a different syntax is required for keys?
  • When I execute the query in SQL Server, it runs just fine.
1

There are 1 answers

1
toscanelli On

Try to surround schema and table names with brackets:

[Sales].[dbo].[MARKETING]

Perhaps you need to surround column names in the same way.