我使用pydoc从sql数据库中获取数据。
我想使用WHERE语句过滤日期。我有:
cursor.execute("SELECT isnull(SOP30200.SOPNUMBE,''), isnull(SOP30200.docdate,'') from SOP30200 where SOP30200.docdate > datetime.datetime(2015,1,1,0,0)")
我得到了一个错误:
ProgrammingError: ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot find either column "datetime" or the user-defined function or aggregate "datetime.datetime", or the name is ambiguous. (4121) (SQLExecDirectW)')
没有WHERE语句,我成功地获得了数据。我确实检查了取出的"docdate“字段的类型,它是datetime.datetime。
编辑:还应该指出提取的日期是在表单datetime.datetime(2013, 5, 8, 0, 0)
中。
发布于 2015-11-18 16:22:54
您需要使用参数注入/内插日期。server正试图按原样运行SQL语句,并期望数据库中存在一个datetime.datetime(..)
函数。
cursor.execute("SELECT isnull(SOP30200.SOPNUMBE,''), isnull(SOP30200.docdate,'') from SOP30200 where SOP30200.docdate > ?", datetime.datetime(2015,1,1,0,0))
发布于 2015-11-18 16:23:57
"datetime.datetime“不是函数,是Python库的类。
可能是:
cursor.execute("SELECT isnull(SOP30200.SOPNUMBE,''), isnull(SOP30200.docdate,'') from SOP30200 where SOP30200.docdate > ?", datetime.datetime(2015,1,1,0,0))
https://stackoverflow.com/questions/33784847
复制相似问题