<?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: SQL syntax for Extract by Attributes with &amp;quot;OR&amp;quot; operator error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/sql-syntax-for-extract-by-attributes-with-amp-amp/m-p/158524#M12147</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just an update: I also tried with this syntax:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
extract = arcpy.sa.ExtractByAttributes (raster, "\VALUE\ = 6 OR \VALUE\ = 8"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And received a different error, this time:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
An expected Field was not found or could not be retrieved properly.
An expected Field was not found or could not be retrieved properly. [VAT_u01002020]
Failed to execute (ExtractByAttributes).
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Which is also a SQL syntax problem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 08:22:24 GMT</pubDate>
    <dc:creator>AnneRiddle</dc:creator>
    <dc:date>2021-12-11T08:22:24Z</dc:date>
    <item>
      <title>SQL syntax for Extract by Attributes with &amp;amp;quot;OR&amp;amp;quot; operator error</title>
      <link>https://community.esri.com/t5/python-questions/sql-syntax-for-extract-by-attributes-with-amp-amp/m-p/158523#M12146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to write a Python code block using Extract by Attributes with a SQL query including the "OR" operator that consistently will not work regardless of the syntax I try. As it is the code block looks like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for raster in arcpy.ListRasters(): 
&amp;nbsp;&amp;nbsp;&amp;nbsp; outpoint = raster + "af"
&amp;nbsp;&amp;nbsp;&amp;nbsp; extract = arcpy.sa.ExtractByAttributes (raster, "/\VALUE/\ = 6 OR /\VALUE/\ = 8")
&amp;nbsp;&amp;nbsp;&amp;nbsp; extract.save (outpoint)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The SQL syntax is directly copied from the Results window, which ran successfully, but throws an error (at the end below) when run in IDLE. I had originally been using the option here (&lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000071000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000071000000&lt;/A&gt;&lt;SPAN&gt;) to escape the double interior quotes with slashes, which did not throw an error but did not extract correctly (it extracted values of 2 and 0 in addition to 6 and 8). I've also tried enclosing the string in triple quotes or escaping the single interior quotes, which both threw errors; IDLE did not recognize the string using the escaping-interior-quotes syntax. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Traceback (most recent call last):
&amp;nbsp; File "S:\FIRE\gdb.py", line 32, in &amp;lt;module&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; extract = arcpy.sa.ExtractByAttributes (raster, "/\VALUE/\ = 6 OR /\VALUE/\ = 8")
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 1117, in ExtractByAttributes
&amp;nbsp;&amp;nbsp;&amp;nbsp; where_clause)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Utils.py", line 47, in swapper
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = wrapper(*args, **kwargs)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 1113, in wrapper
&amp;nbsp;&amp;nbsp;&amp;nbsp; out_raster)
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 474, in &amp;lt;lambda&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return lambda *args: val(*gp_fixargs(args))
ExecuteError: ERROR 999999: Error executing function.
An invalid SQL statement was used.
An invalid SQL statement was used. [VAT_u01002020]
An invalid SQL statement was used. [SELECT * FROM VAT_u01002020 WHERE /\VALUE/\ = 6 OR /\VALUE/\ = 8]
Failed to execute (ExtractByAttributes).
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:22:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-syntax-for-extract-by-attributes-with-amp-amp/m-p/158523#M12146</guid>
      <dc:creator>AnneRiddle</dc:creator>
      <dc:date>2021-12-11T08:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: SQL syntax for Extract by Attributes with "OR" operator error</title>
      <link>https://community.esri.com/t5/python-questions/sql-syntax-for-extract-by-attributes-with-amp-amp/m-p/158524#M12147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just an update: I also tried with this syntax:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
extract = arcpy.sa.ExtractByAttributes (raster, "\VALUE\ = 6 OR \VALUE\ = 8"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And received a different error, this time:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
An expected Field was not found or could not be retrieved properly.
An expected Field was not found or could not be retrieved properly. [VAT_u01002020]
Failed to execute (ExtractByAttributes).
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Which is also a SQL syntax problem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:22:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-syntax-for-extract-by-attributes-with-amp-amp/m-p/158524#M12147</guid>
      <dc:creator>AnneRiddle</dc:creator>
      <dc:date>2021-12-11T08:22:24Z</dc:date>
    </item>
  </channel>
</rss>

