<?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 How can I fix this SQL clause? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-can-i-fix-this-sql-clause/m-p/1250632#M66623</link>
    <description>&lt;P&gt;I have the following code which I'm trying to get to select a row by an input task number.&amp;nbsp; It gives me an error, saying that I have an invalid sql clause. However, looking at the error message, I can't see what's invalid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os
from arcpy import env
task = arcpy.GetParameterAsText(0)
expression = "Task =" + " '" + task +"'"
base_arpx = arcpy.mp.ArcGISProject(r"\\Projects_3\Fig_2_Pro.aprx")
rows = arcpy.da.SearchCursor(r"\\Projects_3\location.gdb\Task_Project_Name_1",
                          "Task; Name; shp_project_points; shp_buffer; workspace;", where_clause=expression)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Here is the error:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;  File "&amp;lt;string&amp;gt;", line 8, in &amp;lt;module&amp;gt;
RuntimeError: An invalid SQL statement was used. [SELECT OBJECTID,Task; Name; shp_project_points; shp_buffer; workspace; FROM Task_Project_Name_1 WHERE Task = '590']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Jan 2023 23:36:39 GMT</pubDate>
    <dc:creator>rescobar</dc:creator>
    <dc:date>2023-01-23T23:36:39Z</dc:date>
    <item>
      <title>How can I fix this SQL clause?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-fix-this-sql-clause/m-p/1250632#M66623</link>
      <description>&lt;P&gt;I have the following code which I'm trying to get to select a row by an input task number.&amp;nbsp; It gives me an error, saying that I have an invalid sql clause. However, looking at the error message, I can't see what's invalid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os
from arcpy import env
task = arcpy.GetParameterAsText(0)
expression = "Task =" + " '" + task +"'"
base_arpx = arcpy.mp.ArcGISProject(r"\\Projects_3\Fig_2_Pro.aprx")
rows = arcpy.da.SearchCursor(r"\\Projects_3\location.gdb\Task_Project_Name_1",
                          "Task; Name; shp_project_points; shp_buffer; workspace;", where_clause=expression)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Here is the error:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;  File "&amp;lt;string&amp;gt;", line 8, in &amp;lt;module&amp;gt;
RuntimeError: An invalid SQL statement was used. [SELECT OBJECTID,Task; Name; shp_project_points; shp_buffer; workspace; FROM Task_Project_Name_1 WHERE Task = '590']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 23:36:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-fix-this-sql-clause/m-p/1250632#M66623</guid>
      <dc:creator>rescobar</dc:creator>
      <dc:date>2023-01-23T23:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: How can I fix this SQL clause?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-fix-this-sql-clause/m-p/1250634#M66624</link>
      <description>&lt;P&gt;You use a comma after the first attribute field in the SQL query (OBJECTID) but then you switch to semi-colons. Try using all commas in your attribute field list inside the SQL query string.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 23:43:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-fix-this-sql-clause/m-p/1250634#M66624</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2023-01-23T23:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: How can I fix this SQL clause?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-fix-this-sql-clause/m-p/1250635#M66625</link>
      <description>&lt;P&gt;It isn't just a comma or semicolon issue, the SearchCursor takes a list of strings, not a string of delimited fields.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2023 23:44:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-fix-this-sql-clause/m-p/1250635#M66625</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2023-01-23T23:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: How can I fix this SQL clause?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-fix-this-sql-clause/m-p/1250668#M66626</link>
      <description>&lt;P&gt;Assuming&amp;nbsp;"Task", "Name", "shp_project_points", "shp_buffer", "workspace" are all fields in your featureclass.&amp;nbsp; As&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp;notes, this parameter needs to be a list of field names, not a single string.&lt;/P&gt;&lt;P&gt;Change&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"Task; Name; shp_project_points; shp_buffer; workspace;"&lt;/LI-CODE&gt;&lt;P&gt;To&lt;/P&gt;&lt;LI-CODE lang="python"&gt;["Task", "Name", "shp_project_points", "shp_buffer", "workspace"]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 04:30:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-fix-this-sql-clause/m-p/1250668#M66626</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2023-01-24T04:30:24Z</dc:date>
    </item>
  </channel>
</rss>

