title: Capture stored procedure output with python pyodbc
body: <p>I have a stored procedure which I am calling using Python scripts and Pyodbc module. The code looks like this:</p>
  
  <pre><code>import pyodbc
  pyodbc.pooling=False
  oConnexion = pyodbc.connect("driver={Teradata};dbcname=myServer;DefaultDatabase=myDB;uid=myUser;pwd=myPassword;charset=utf8;", autocommit=True)
  oConnexion.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8')
  oConnexion.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8')
  oConnexion.setencoding(encoding='utf-8')
  oCursor = oConnexion.cursor()
  oQueryRegisterBatch = "CALL DEV_AUDIT.SP_AUDIT_BATCH('ED_DATA_QUALITY_MANUAL', 'REGISTER', '1900-01-01 00:00:00.000000', '2999-12-31 00:00:00.000000');"
  oCursor.execute(oQueryRegisterBatch)
  for row in oCursor:
      print (row)
  </code></pre>
  
  <p>The stored procedure creates a new record and returns the record id (BATCH_KEY). When I execute the stored procedure in Teradata, it returns the BATCH_KEY properly but I am not able to capture it in Python. I get the following error message instead of the value:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  pyodbc.ProgrammingError: No results.  Previous SQL was not a query.
  </code></pre>
  
  <p>I could retrieve the BATCH_KEY by querying on the table after calling the stored procedure but I would like to avoid. Could you please advise how to capture the output of the stored procedure?</p>
  
  <p>Thanks</p>