I came across the below post, which is my exact situation. I have a large SQL query which has the below format:
SET NOCOUNT ON
CREATE TABLE x
INSERT INTO x
CREATE TABLE y
INSERT INTO y
.
.
.
SELECT * FROM x join y
where a
UNION
SELECT * FROM x join y
where b
The query works perfectly fine, returning over 15k rows as intended. When I try and read this into a dataframe in python, I get the 'NoneType' object is not iterable error, as described in the below link. I see the original poster converted his query into a stored procedure. I am wondering if there is another way to resolve this error, without writing a stored procedure.
Python Pandas read_sql_query “'NoneType' object is not iterable” error
UPDATE - inserting python code
server = 'server'
query = 'test.sql'
db ='db'
conn = pyodbc.connect(r'Driver={SQL Server};Server=' + dbserver + ';Database=' + database + ';Trusted_Connection=yes;')
fd = open(query, 'r')
df = pd.read_sql_query(fd.read(),conn)
fd.close()
conn.close()