<?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 Building SQL Expression using printed results? in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/building-sql-expression-using-printed-results/m-p/1196706#M57904</link>
    <description>&lt;P&gt;I run a searchcursor that prints results. How do I use those results to build an SQL Expression in Python?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;lyr = "layer name"
events = arcpy.da.SearchCursor(lyr, ['Event'])
unique_events = list(set([row[0] for row in events]))
unique_events
print(unique_events)&lt;/LI-CODE&gt;&lt;P&gt;I then get values&lt;/P&gt;&lt;LI-CODE lang="c"&gt;[1, 2, 3, 4, 5, 6]&lt;/LI-CODE&gt;&lt;P&gt;How do I take those values in python and insert them in sql expression for whats in the ()?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;arcpy.management.SelectLayerByAttribute("Lyer2", "NEW_SELECTION", "Event IN ()", None)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jul 2022 12:28:37 GMT</pubDate>
    <dc:creator>Davec43</dc:creator>
    <dc:date>2022-07-28T12:28:37Z</dc:date>
    <item>
      <title>Building SQL Expression using printed results?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/building-sql-expression-using-printed-results/m-p/1196706#M57904</link>
      <description>&lt;P&gt;I run a searchcursor that prints results. How do I use those results to build an SQL Expression in Python?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;lyr = "layer name"
events = arcpy.da.SearchCursor(lyr, ['Event'])
unique_events = list(set([row[0] for row in events]))
unique_events
print(unique_events)&lt;/LI-CODE&gt;&lt;P&gt;I then get values&lt;/P&gt;&lt;LI-CODE lang="c"&gt;[1, 2, 3, 4, 5, 6]&lt;/LI-CODE&gt;&lt;P&gt;How do I take those values in python and insert them in sql expression for whats in the ()?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;arcpy.management.SelectLayerByAttribute("Lyer2", "NEW_SELECTION", "Event IN ()", None)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 12:28:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/building-sql-expression-using-printed-results/m-p/1196706#M57904</guid>
      <dc:creator>Davec43</dc:creator>
      <dc:date>2022-07-28T12:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: Building SQL Expression using printed results?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/building-sql-expression-using-printed-results/m-p/1196942#M57911</link>
      <description>&lt;P&gt;one way:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;sql = "Event IN(" + ','.join(map(str,unique_events)) + ")"

arcpy.management.SelectLayerByAttribute("Lyer2", "NEW_SELECTION", sql, None)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;sql&lt;/P&gt;&lt;P&gt;'Event IN(1,2,3,4,5,6)'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;R_&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 18:10:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/building-sql-expression-using-printed-results/m-p/1196942#M57911</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-07-28T18:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Building SQL Expression using printed results?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/building-sql-expression-using-printed-results/m-p/1196967#M57914</link>
      <description>&lt;P&gt;You can streamline it by not converting to list but a tuple.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;lyr = "layer name"
events = arcpy.da.SearchCursor(lyr, ['Event'])
unique_events = tuple(set([row[0] for row in events]))
arcpy.management.SelectLayerByAttribute("Lyer2", "NEW_SELECTION", f"Event IN {unique_events}", None)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 28 Jul 2022 18:31:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/building-sql-expression-using-printed-results/m-p/1196967#M57914</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2022-07-28T18:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Building SQL Expression using printed results?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/building-sql-expression-using-printed-results/m-p/1197939#M58024</link>
      <description>&lt;P&gt;Awesome it worked!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 12:57:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/building-sql-expression-using-printed-results/m-p/1197939#M58024</guid>
      <dc:creator>Davec43</dc:creator>
      <dc:date>2022-08-01T12:57:04Z</dc:date>
    </item>
  </channel>
</rss>

