Python pyodbc sql 无法绑定查询

Python pyodbc sql query could not be bound

我正在尝试在 python pyodbc 模块中获取日期此查询:

SELECT distinct
regs.[workerID] as ewid_1
,workers.[workerID] as ewid_2
,regs.[deviceId]
,workers.[workerFirstName]
,workers.[workerLastName]
,workers.[workerDomainID]
,workers.[department]
,regs.[applicationVersion]
,regs.[modifyDate]
,regs.[locomotiveNo]
,regs.[deviceNo]
,regs.[manufacturer]
,regs.[model]
,regs.[osSystemName]
,regs.[localDateTime]
,regs.[machineName]
,regs.[ip]
,regs.[simSubscriberID]
,regs.[simRegistration]
,regs.[simIccID]
,regs.[simState]
FROM [PS_SLK].[dbo].[ps_slk_registeredDevices] regs
join [PS_SLK].[dbo].[ps_slk_workers] workers
on regs.[workerID] = workers.[workerID]
where workers.workerDomainID not in ('kolejadmin','02pdawic') and 
regs.modifyDate > '2021-01-01' and workers.workerDomainID is not null and 
regs.workerID is not null

不幸的是我得到了这个错误:

pyodbc.ProgrammingError: ('42000', '[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The multi-part identifier "regs.workerID" could not be bound. (4104)...

在 SSMS 中一切正常,我没有收到任何警告。 [PS_SLK].[dbo].[ps_slk_registeredDevices] 是 instacne 是数据库 PS_SLK 和 table [ps_slk_registeredDevices 的一个实例。我尝试从同一个数据库中加入两个 table。

我搜索了一些解决方案,但不明白我做错了什么。我尝试更改符号或使用 JOIN,但在 pyodbc 中不起作用。

谁能解释一下我做错了什么?

它正在工作。我需要重新启动 venv。