title: Working with Cursors in Python
body: <p>Searched the web and this forum without satisfaction.  Using Python 2.7 and pyODBC on Windows XP.  I can get the code below to run and generate two cursors from two different databases without problems.  Ideally, I'd then like to join these result cursors thusly:</p>
  
  <pre><code>SELECT a.state, sum(b.Sales) 
  FROM cust_curs a 
      INNER JOIN fin_curs b 
      ON a.Cust_id = b.Cust_id 
  GROUP BY a.state
  </code></pre>
  
  <p>Is there a way to join cursors using SQL statements in python or pyODBC?  Would I need to store these cursors in a common DB (SQLite3?) to accomplish this?  Is there a pure python data handling approach that would generate this summary from these two cursors?</p>
  
  <p>Thanks for your consideration.</p>
  
  <p>Working code:</p>
  
  <pre><code>import pyodbc
  
  #
  # DB2 Financial Data Cursor
  #
  cnxn = pyodbc.connect('DSN=DB2_Fin;UID=;PWD=')
  fin_curs = cnxn.cursor()
  
  fin_curs.execute("""SELECT Cust_id, sum(Sales) as Sales
                      FROM Finance.Sales_Tbl
                      GROUP BY Cust_id""")
  
  #
  # Oracle Customer Data Cursor
  #
  cnxn = pyodbc.connect('DSN=Ora_Cust;UID=;PWD=')
  cust_curs = cnxn.cursor()
  
  cust_curs.execute("""SELECT Distinct Cust_id, gender, address, state  
                      FROM Customers.Cust_Data""")
  </code></pre>