Python/pyodbc WHERE语句过滤日期?

2024-09-28 17:02:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我用pydoc从sql数据库中获取数据。在

我想用WHERE语句过滤日期。我有:

cursor.execute("SELECT isnull(SOP30200.SOPNUMBE,''), isnull(SOP30200.docdate,'') from SOP30200 where SOP30200.docdate > datetime.datetime(2015,1,1,0,0)")

我得到了一个错误:

^{pr2}$

没有WHERE语句,我成功地获得了数据。我确实检查了拉出的“docdate”字段的类型日期时间。日期时间. 在

EDIT:还应该指出提取的日期的格式是datetime.datetime(2013, 5, 8, 0, 0)


Tags: from数据库executesqldatetime时间语句where
2条回答

““日期时间。日期时间“不是SQL函数,是Python类的标准库。在

可能是:

cursor.execute("SELECT isnull(SOP30200.SOPNUMBE,''), isnull(SOP30200.docdate,'') from SOP30200 where SOP30200.docdate > ?", datetime.datetime(2015,1,1,0,0))

您需要使用参数注入/插入日期。SQL 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))

请参见http://mkleehammer.github.io/pyodbc/-参数部分

相关问题 更多 >