我正在研究python,我需要将查询结果转换为电子邮件,并且使用了漂亮的表并将SQL查询结果转换为表,但是问题是我体内需要此输出表电子邮件。
我们该怎么做?
import pyodbc
from prettytable import PrettyTable
xi = PrettyTable(['Job ID','Desc'])
xi.padding_width = 1
con = pyodbc.connect('DRIVER={SQL Server};SERVER=SNLdb2;DATABASE=InternalUseOnly;Trusted_Connection=yes')
cur = con.cursor()
db_cmd = ("""select pi.ProcessInstanceAppianID,pi.ProcessInstanceDescription
from InternalUseOnly..ProcessInstance pi
where pi.KeyProcessStream in (11994)
and UpdOperation <> 2
and pi.ProcessInstanceCompleted is null
order by pi.KeyProcessInstance
""")
res = cur.execute(db_cmd)
for data in res:
xi.add_row([data[0],data[1]])
print(xi)