我正在尝试使用python从SQL数据库获取信息
当SQL语句很简单时,我能够连接和检索数据,比如#cursor.execute("SELECT * FROM Client WHERE UsesTimesheet = 1 ORDER BY ClientName")
但是,当我转到一个更复杂的语句时,会得到如下所示的错误Traceback (most recent call last):
File "F:\Python\Test - AutoCad.py", line 30, in
where jobnum = 1205992")
File "C:\Python26\ArcGIS10.0\lib\site-packages\pymssql.py", line 196, in execute
raise OperationalError, e[0]
OperationalError: SQL Server message 102, severity 15, state 1, line 1:
Incorrect syntax near 'jobnum'.
当我使用Microsoft SQL 2008客户端而不是python中时,此语句有效。
我做错什么了?对于复杂的语句,我应该使用SQLAlchemy吗?
下面是当前代码import pymssql
import _mssql
import sys
# Connect to db using Windows Integrated Authentication.
conn = _mssql.connect(server='000.000.0.0', databa