import requests
import json
from datetime import datetime
import pymssql
server = 'devserver'
database = 'devdb'
username = 'devuser'
password = 'passwd'
connection = pymssql.connect(server, username, password, database)
query = "select Name,DateTimeStamp from Newtable where DateTimeStamp >= (SELECT DATEADD(day, -1, GETDATE())"
cursor = connection.cursor()
cursor.execute(query)
row = cursor.fetchone()
cursor.close()
print(row)
我得到以下异常:
_mssql.MSSQLDatabaseException: (102, b"Incorrect syntax near ')'.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")
如果我改为 query = "SELECT GETDATE()"
工作,则相同的代码。谁能帮我解决这个问题?
数据库条目,