安装
pip install pyodbc
导入
import pyodbc
建立连接
con = pyodbc.connect('DRIVER={SQL Server};SERVER=192.168.202.173;DATABASE=AIS20230802091529;UID=sa;PWD=chief.cc1993')
游标
cursor=con.cursor()
查询
sql="select * from T_SAL_OUTSTOCK where FBillNo='XSCKD000002'"
cursor.execute(sql)
rows=cursor.fetchall()
完整代码
import pyodbc
con = pyodbc.connect('DRIVER={SQL Server};SERVER=192.168.202.173;DATABASE=AIS20230802091529;UID=sa;PWD=chief.cc1993')
print(con)
cursor=con.cursor()
sql="select * from T_SAL_OUTSTOCK where FBillNo='XSCKD000002'"
cursor.execute(sql)
rows=cursor.fetchall()
print(rows)
输出