Invalid MS SQL object name

I have

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

which gives me a trace error:

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

I have a few other lines of code:

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

which are exactly the same, with the exception of the column name, which give me no error. I'm not sure what my mistake is.

Note:

  • I already checked the table for the column name to make sure it exists.
  • I noticed that this column is the key for this table. Perhaps keys require a different syntax?
  • When I execute a query in SQL Server, it works fine.
+4
source share
1 answer

Try copying the names of schemas and tables in brackets:

[Sales].[dbo].[MARKETING]

You may need to surround the column names in the same way.

0
source

Source: https://habr.com/ru/post/1532178/


All Articles