我不可能在2019:00开发一个查询,但我不能用一个日期和日期之间插入一个查询和一个查询。我想从用户那里得到日期。如果真的很简单,我很抱歉
我在网上搜索,尝试了不同的符号,但我无法解决这个问题import pyodbc
from tkinter import *
import datetime
root = Tk()
root.configure(background='blanched almond')
root.geometry("700x600")
root.title("QUERY PROGRAM ")
label1= Label(root,text=" QUERY PROGRAM ",bg='blanched almond',fg='LightSkyBlue4',font="Arial 12 bold")
label1.pack()
label2=Label(root,text="Please enter the first date such as 2019-05-22 00:00:00",bg='blanched almond')
label2.place(x=0,y=100)
label3=Label(root,text="Please enter the last date such as 2019-05-24 00:00:00",bg='blanched almond')
label3.place(x=0,y=160)
date1_text=StringVar()
date2_text=StringVar()
entry1=Entry(root, textvariable=date1_text)
entry1.place(x=10,y=130)
entry2=Entry(root, textvariable=date2_text)
entry2.place(x=10,y=190)
date1=date1_text.get()
date2=date2_text.get()
def query():
con= pyodbc.connect("DRIVER={SQL Server}; server=server;database=TestVT;uid=da;pwd=1234")
cur = con.cursor()
cur.execute("select date from TestVT.data where date >='%s' and date < '%s' and datetype in (4,5,6,7,13)" %(date1,date2))
data =cur .fetchall()
for i in data:
#print (f" ID = {i[0]} NAME={i[1]}")
print (i)
cur.close()
con.close()
button1=Button(root,text="QUERY",command=query )
button1.place(x=300,y=280)
root.mainloop()
ıf i remove“from%s like where date>;=%s,则在关键字“and”附近收到语法不正确的消息。谢谢你的努力