<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to insert a row with arcpy (puthon2) in Database SQL Server in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-insert-a-row-with-arcpy-puthon2-in-database/m-p/1288539#M67631</link>
    <description>&lt;P&gt;You could also try straight sql:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pyodbc

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=servername\SQLEXPRESS;'
                      'Database=db;'
                      'Trusted_Connection=yes;')

cursor = conn.cursor()

for item in ItemsToAddList:
    cursor.execute("""INSERT INTO table (Id, Nom, TypeLayer, [Order]) VALUES ({0},{1},{2},{3})""".format(item[0], item[1], item[2], item[3]))
    # or if the table only consists of these four fields and you insert 4 items, you can maybe drop the field assignment: cursor.execute("""INSERT INTO table VALUES ({0},{1}, {2},{3})""".format(item[0], item[1], item[2], item[3]))
conn.commit()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2023 12:29:54 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2023-05-12T12:29:54Z</dc:date>
    <item>
      <title>how to insert a row with arcpy (puthon2) in Database SQL Server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-insert-a-row-with-arcpy-puthon2-in-database/m-p/1287672#M67620</link>
      <description>&lt;P&gt;I'm currently having a problem when using ArcPy (Python 2) to insert a row into a table using a SQL server database., Since this table contains a "Order" field that is a keyword in SQL., here is an example in the names of the fields to insert:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Fields = [‘Id’, ‘Nom’, ‘TypeLayer’, ‘Order’]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;And I used &lt;STRONG&gt;arcpy.da.InsertCursor(table_path, Fields) &lt;/STRONG&gt;to insert the row.&lt;/P&gt;&lt;P&gt;When I run the script, I got the following error:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RuntimeError&amp;nbsp;: Invalid SQL syntax [[Microsoft][ODBC Driver 17 for SQL Server][SQL Server] Syntaxe incorrecte vers le mot clé ‘Order’]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Then, after researching on the net, I found solutions that say to put the keyword 'Order' in brackets.&lt;/P&gt;&lt;P&gt;Fields = [‘Id’, ‘Nom’, ‘TypeLayer’, ‘&lt;STRONG&gt;[Order]&lt;/STRONG&gt;’]&lt;/P&gt;&lt;P&gt;I always had the same error:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RuntimeError&amp;nbsp;: Invalid SQL syntax [[Microsoft][ODBC Driver 17 for SQL Server][SQL Server] Syntaxe incorrecte vers le mot clé ‘Order’]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 13:06:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-insert-a-row-with-arcpy-puthon2-in-database/m-p/1287672#M67620</guid>
      <dc:creator>KamelAmellal</dc:creator>
      <dc:date>2023-05-10T13:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to insert a row with arcpy (puthon2) in Database SQL Server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-insert-a-row-with-arcpy-puthon2-in-database/m-p/1288222#M67621</link>
      <description>&lt;P&gt;Ha! That's a very unfortunate situation. Can you insert the row if you don't use the Order field? If so, do that, then update the row later with your Order value. Not efficient, but that is the first thing that comes to mind. Or if this feature class has little or no dependencies, then maybe consider renaming the field.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 16:10:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-insert-a-row-with-arcpy-puthon2-in-database/m-p/1288222#M67621</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-05-11T16:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to insert a row with arcpy (puthon2) in Database SQL Server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-insert-a-row-with-arcpy-puthon2-in-database/m-p/1288539#M67631</link>
      <description>&lt;P&gt;You could also try straight sql:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pyodbc

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=servername\SQLEXPRESS;'
                      'Database=db;'
                      'Trusted_Connection=yes;')

cursor = conn.cursor()

for item in ItemsToAddList:
    cursor.execute("""INSERT INTO table (Id, Nom, TypeLayer, [Order]) VALUES ({0},{1},{2},{3})""".format(item[0], item[1], item[2], item[3]))
    # or if the table only consists of these four fields and you insert 4 items, you can maybe drop the field assignment: cursor.execute("""INSERT INTO table VALUES ({0},{1}, {2},{3})""".format(item[0], item[1], item[2], item[3]))
conn.commit()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 12:29:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-insert-a-row-with-arcpy-puthon2-in-database/m-p/1288539#M67631</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-05-12T12:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to insert a row with arcpy (puthon2) in Database SQL Server</title>
      <link>https://community.esri.com/t5/python-questions/how-to-insert-a-row-with-arcpy-puthon2-in-database/m-p/1288589#M67633</link>
      <description>&lt;P&gt;Keep in mind you'll need to use the versioned view if you're editing versioned data with SQL. It's more complicated if you're working in a named version rather than the Default version.&lt;/P&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/en/arcmap/latest/manage-data/using-sql-with-gdbs/edit-versioned-data-using-sql-sqlserver.htm" target="_blank"&gt;Edit versioned data in SQL Server using SQL—ArcMap | Documentation (arcgis.com)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 14:19:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-insert-a-row-with-arcpy-puthon2-in-database/m-p/1288589#M67633</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-05-12T14:19:19Z</dc:date>
    </item>
  </channel>
</rss>

