title: pyodbc - inserting selected rows (access mdb)
body: <p>When inserting selected records / rows from an Access .mdb table, I find a "<code>Syntax error in INSERT INTO statement. (-3502)</code>" on line 23 of this code block.</p>
  
  <p>What I want to happen is to </p>
  
  <ol>
  <li>Create a table '65001'</li>
  <li>Select the first 65000 rows from table 'LMR_Combined'</li>
  <li>Insert those selected rows into the newly created '65001' table.</li>
  </ol>
  
  <p>What syntax mistake is in this INSERT INTO statement that's preventing successful execution?</p>
  
  <pre><code>import pyodbc
  DBFile = r'C:\Python27\FCC_Processing\LMR Combined.mdb'
  conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ='+DBFile)
  
  cursor = conn.cursor()
  
  
  # Creates a table "65001" in the MDB that matches the schema of table "LMR_Combined"
  string = "CREATE TABLE 65001(OBJECTID integer, Unique_ID varchar(255), LICENSEE_NAME varchar(255))"
  
  cursor.execute(string)
  
  # Selects 65000 records from table "LMR_Combined"
  cursor.execute('select OBJECTID, Unique_ID, LICENSEE_NAME from LMR_Combined where OBJECTID &gt; 0 and OBJECTID &lt; 65001')
  
  row = cursor.fetchone()
  
  # For debugging, print a line
  if row:
      print row
  
  # Inserts the 65000 rows into the new table "65001"
  cursor.execute('insert OBJECTID, Unique_ID, LICENSEE_NAME into 65001')
  
  conn.commit()
  </code></pre>
  
  <p>Thanks in advance</p>