title: Function sequence error in PYODBC
body: <p>I am using <code>pyodbc</code> to connect to a database and extract certain data from it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>con = pyodbc.connect("driver={SQL Server};server= MyServer;database= MyDatabase;trusted_connection=true") 
  
  cursor = con.cursor()
  
  SQL_command = """
                        SELECT RowID = ISNULL
                        (
                            (
                                SELECT TOP 1 RowID
                                FROM [MyDatabase].[admin].[MyTable] 
                                WHERE [queue] = ? and processed IS NULL
                            )
                            ,-1
                        )
                    """
  
  cursor.execute(SQL_command, queueNumber)
  
  cursor.commit()
  
  con.commit()
  
  result_set = cursor.fetchall()
  </code></pre>
  
  <p>And I got following error after I run above code:</p>
  
  <blockquote>
    <p>pyodbc.Error: ('HY010', '[HY010] [Microsoft][ODBC SQL Server
    Driver]Function sequence error (0) (SQLFetch)')</p>
  </blockquote>
  
  <p>May I know what caused such problem, and how can I fix it?</p>
  
  <p>Thanks.</p>