所以我有一个存储过程,我想连接到它并在 python 中执行,这样我就可以将数据导出为一个花哨的表。
这是我使用的代码,注释是我尝试过的代码。
import plotly as py
import plotly.figure_factory as ff
import pandas as pd
import pypyodbc
import pyodbc
import datetime
import seaborn as sns
import matplotlib.pyplot as plt
#force the ODBC driver to use case-sensitive column names
pypyodbc.lowercase = True
startdate = '2018-10-23 08:00'
enddate = '2018-10-24 12:00'
params = startdate,enddate
##Establishing a connection to SQL database
connection = pypyodbc.connect('Driver={SQL Server};'
'Server=LOLOL;'
'Database=LOL_Collection;'
'trusted_connection=yes;')
crsr = connection.cursor()
SQL = """
SET NOCOUNT ON
declare @start = '2018-10-23 08:00'
declare @end = '2018-10-24 12:00'
exec [dbo].[AM_SIGNAL_Histogram] @start, @end
"""
#SQL = """
#
#exec [dbo].[AM_SIGNAL_Histogram] @start, @end
#
#"""
#result = crsr.execute(SQL)
#
#print(result.fetchall())
df = pd.read_sql(SQL,connection)
connection.close()
这是我不断收到的错误:
ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server 驱动程序][SQL Server]'='附近的语法不正确。")
感谢您的帮助,肯尼斯
相关分类