I am trying to execute a sql and save a result into Panda Dataframe. here is my code.
dbserver = 'validserver'
filename = 'myquery.sql'
database ='validdb'
conn = pyodbc.connect(r'Driver={SQL Server};Server=' + dbserver +
';Database=' + database + ';Trusted_Connection=yes;')
fd = open(filename, 'r')
resultingData = pd.read_sql_query(fd.read(),conn)
fd.close()
conn.close()
line pd.read_sql_query(fd.read(),conn)
continues to give me error
'NoneType' object is not iterable” error
I can run myquery.sql in a sql server window with results. I do have SET NOCOUNT ON;
Any clue what am I missing here and how do I debug this? myquery.sql has few #temp tables and joins. Result has about 75k rows. Thanks all.
Update:
I can not post the exact query but this is how query looks like.
SET NOCOUNT ON;
SELECT SourceID, PeriodEndDate = MAX(PeriodEndDate)
INTO #SourceDate
FROM table1
WHERE PERIODENDDATE <= 20171229
GROUP BY SourceID
SELECT RS.*, R.TypeCode INTO #final
FROM table2 RS
INNER JOIN #SourceDate SD ON SD.id = RS.id
INNER JOIN table3 R ON R.id = RS.id
select * from #final