<?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: arcpy select by attribute doesn't work? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382125#M69871</link>
    <description>&lt;P&gt;Dear EdMorris,&lt;/P&gt;&lt;P&gt;I hope you are doing great when reading this message,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SQL keywords are not case-sensitive&lt;/STRONG&gt;&lt;SPAN&gt;, which means you can write them in uppercase, lowercase, or a combination of both.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Have a great day&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Feb 2024 12:05:50 GMT</pubDate>
    <dc:creator>Amir-Sarrafzadeh-Arasi</dc:creator>
    <dc:date>2024-02-14T12:05:50Z</dc:date>
    <item>
      <title>arcpy select by attribute doesn't work?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382093#M69867</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;try to select by attributes a feature class, but it doesn't work?&lt;/P&gt;&lt;P&gt;Any ideas why?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields = ["OBJECTID", "TARGET_FID"]
with arcpy.da.SearchCursor(outMerge, fields) as cursor:
    for row in cursor:
        if row[1] &amp;gt; 0:
            
            selClause = str(row[1])
            selClause1 = "OBJECTID = {0} Or TARGET_FID = {0}".format(selClause)
            print (selClause1)
        
            arcpy.management.SelectLayerByAttribute(outMerge, "NEW_SELECTION", selClause1)
            result = arcpy.management.GetCount(outMerge)
            print (result[0])
            if int(result[0]) &amp;gt; 1:
                outIntersLines = "outIntersLines_{}".format(row[0])
                # arcpy.management.PointsToLine(outMerge, outIntersLines)
            else:
                continue
        else: 
            continue&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The print statements line 9 looks ok for me:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;OBJECTID = 1 Or TARGET_FID = 1&lt;BR /&gt;But there's nothing selected?&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 10:32:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382093#M69867</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2024-02-14T10:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy select by attribute doesn't work?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382108#M69868</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;So if you run a "SQL query" and no rows / features are selected then it means you have a poorly constructed where clause.&lt;/P&gt;&lt;P&gt;I think 'Or' (line 7 in your code snippet above) needs to be capitalised (I think...).&lt;/P&gt;&lt;P&gt;Many thanks ed&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 11:23:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382108#M69868</guid>
      <dc:creator>EdMorris</dc:creator>
      <dc:date>2024-02-14T11:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy select by attribute doesn't work?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382112#M69869</link>
      <description>&lt;P&gt;I am assuming outMerge is a path to data? I think you are calling GetCount on the input Feature Class, instead you need to wrap a layer using arcpy.management.MakeFeatureLayer and use that as the first to Select by Attributes, and then GetCount on the layer. Alternatively use getOutput on Select&amp;nbsp; by Attributes - this exposes a layer created by the tool which will have the count on it. call GetCount on that.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;            sel_lyr = arcpy.management.SelectLayerByAttribute(outMerge, "NEW_SELECTION", selClause1).getOutput(0)
            count1 = int(arcpy.management.GetCount(sel_lyr).getOutput(0))&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 14 Feb 2024 11:34:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382112#M69869</guid>
      <dc:creator>RHmapping</dc:creator>
      <dc:date>2024-02-14T11:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy select by attribute doesn't work?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382123#M69870</link>
      <description>&lt;P&gt;Dear Johannes,&lt;/P&gt;&lt;P&gt;I hope you are doing well,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem of your script is this, in the for loop you are generating a new SQL clause, but you should add to the previous SQL clause and apply the select method out of for loop.&lt;/P&gt;&lt;P&gt;please check tthe below image, which is correct version of your script.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SQL.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/94723iBAC9092AFDCF3B42/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SQL.png" alt="SQL.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please make sure about the 'outMerge',&lt;/P&gt;&lt;P&gt;If you have more info please let me know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps, Stay Safe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 12:07:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382123#M69870</guid>
      <dc:creator>Amir-Sarrafzadeh-Arasi</dc:creator>
      <dc:date>2024-02-14T12:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy select by attribute doesn't work?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382125#M69871</link>
      <description>&lt;P&gt;Dear EdMorris,&lt;/P&gt;&lt;P&gt;I hope you are doing great when reading this message,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SQL keywords are not case-sensitive&lt;/STRONG&gt;&lt;SPAN&gt;, which means you can write them in uppercase, lowercase, or a combination of both.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Have a great day&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 12:05:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382125#M69871</guid>
      <dc:creator>Amir-Sarrafzadeh-Arasi</dc:creator>
      <dc:date>2024-02-14T12:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy select by attribute doesn't work?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382126#M69872</link>
      <description>&lt;P&gt;thanks!&lt;/P&gt;&lt;P&gt;... as i said... "I think..."&lt;/P&gt;&lt;P&gt;happy to be corrected&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 12:11:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382126#M69872</guid>
      <dc:creator>EdMorris</dc:creator>
      <dc:date>2024-02-14T12:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy select by attribute doesn't work?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382137#M69873</link>
      <description>&lt;P&gt;Thank you ...&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 12:26:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382137#M69873</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2024-02-14T12:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy select by attribute doesn't work?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382138#M69874</link>
      <description>&lt;P&gt;Hello Amir,&lt;/P&gt;&lt;P&gt;thank you for your help - but i think RHmapping was right about the missing make feature layer ...&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 12:30:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382138#M69874</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2024-02-14T12:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy select by attribute doesn't work?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382140#M69875</link>
      <description>&lt;P&gt;Hello Johannes,&lt;/P&gt;&lt;P&gt;As I mentioned you should be sure the 'outMerge' is feature layer, but if you have a feature layer with high number of records, calling arcpy inside a for loop in each iteration is not efficient method.&lt;/P&gt;&lt;P&gt;If you try the both solutions in your feature layer data, you will see the differences.&lt;/P&gt;&lt;P&gt;I just tried in a feature layer with 257 records,&lt;/P&gt;&lt;P&gt;first one took 7.94 seconds.&lt;/P&gt;&lt;P&gt;second one took 0.18 seconds.&lt;/P&gt;&lt;P&gt;Anyway, I am so happy you find your solution,&lt;/P&gt;&lt;P&gt;Best ragrads&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 12:48:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382140#M69875</guid>
      <dc:creator>Amir-Sarrafzadeh-Arasi</dc:creator>
      <dc:date>2024-02-14T12:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy select by attribute doesn't work?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382171#M69877</link>
      <description>&lt;P&gt;Looks like you got a solution, but for next time:&lt;/P&gt;&lt;P&gt;If you want to use a selection as input into something else, you need to make that selection a variable.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;outMerge = arcpy.management.SelectLayerByAttribute(outMerge, 
                                                   "NEW_SELECTION", 
                                                   selClause1)
result = arcpy.management.GetCount(outMerge,...)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2024 14:05:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-select-by-attribute-doesn-t-work/m-p/1382171#M69877</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-02-14T14:05:18Z</dc:date>
    </item>
  </channel>
</rss>

