title: Python Pandas read_sql_query “'NoneType' object is not iterable” error
body: <p>I am trying to execute a sql and save a result into Panda Dataframe. here is my code. </p>
  
  <pre><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()
  </code></pre>
  
  <p>line <code>pd.read_sql_query(fd.read(),conn)</code> continues to give me error 
  'NoneType' object is not iterable” error</p>
  
  <p>I can run myquery.sql in a sql server window with results. I do have <code>SET NOCOUNT ON;</code></p>
  
  <p>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. </p>
  
  <p><strong>Update:</strong> </p>
  
  <p>I can not post the exact query but this is how query looks like. </p>
  
  <pre><code>SET NOCOUNT ON;
  
  SELECT SourceID, PeriodEndDate = MAX(PeriodEndDate)
  INTO #SourceDate 
  FROM table1
  WHERE PERIODENDDATE &lt;= 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
  </code></pre>