<?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: Multivalue query in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649662#M50566</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Works great thank you to both of you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 27 Mar 2013 13:27:39 GMT</pubDate>
    <dc:creator>TonyAlmeida</dc:creator>
    <dc:date>2013-03-27T13:27:39Z</dc:date>
    <item>
      <title>Multivalue query</title>
      <link>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649656#M50560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to create a script that allow me to enter more then one value to search, select and create a new feature from the selected. My script runs and finished fine but produces no out feature class. I am not sure if i am doing it correctly or not but any help would be great. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp; arcpy.env.overwriteOutput = True mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] lyr = arcpy.mapping.ListLayers(mxd, "Taxparcels")[0]&amp;nbsp; #Define input/output input = arcpy.GetParameterAsText(0) fieldName = arcpy.GetParameterAsText(1) values = arcpy.GetParameterAsText(2) output = arcpy.GetParameterAsText(3)&amp;nbsp; #Build the where clause queryJoin = "' OR " + fieldName + " = '" whereClause = fieldName + " = '" + queryJoin.join(values) + "'"&amp;nbsp; #Select(input, output, whereClause) arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause) if int(arcpy.GetCount_management("Taxparcels").getOutput(0)) &amp;gt; 0:&amp;nbsp; &amp;nbsp;&amp;nbsp; arcpy.Select_analysis("Taxparcels", output) &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Script parameters&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;are attached.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Mar 2013 19:38:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649656#M50560</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2013-03-26T19:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Multivalue query</title>
      <link>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649657#M50561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you are only making selections from one field you can make a much easier query using the 'IN' command.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Instead of&amp;nbsp; this&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;query = 'field = x or field = y or field = z' #etc&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;It would be this&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;query = 'field in (x, y, z)'&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;You also don't need to run a separate selection when using the select tool, you can input the where clause directly in the tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The main issue you are probably having is your values variable is a string and you are trying to add it how generally lists are used. How do you plan on having your users input multiple values? You would need to post a sample of your valid field values and the actual properties of your values parameter to get more help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Mar 2013 19:50:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649657#M50561</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-03-26T19:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Multivalue query</title>
      <link>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649658#M50562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;the values would be manually entered like this (R12351, R12352). I have attached a sample of the data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for replying.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Mar 2013 20:17:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649658#M50562</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2013-03-26T20:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: Multivalue query</title>
      <link>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649659#M50563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Something like this should work. Should be all you need after your inputs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Build the where clause
whereClause = "{0} in ('{1}')".format(fieldName, "','".join(values.split(';')))

#Select(input, output, whereClause)

if int(arcpy.GetCount_management(lyr).getOutput(0)) &amp;gt; 0:

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Select_analysis(lyr, output, whereClause)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:33:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649659#M50563</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T03:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: Multivalue query</title>
      <link>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649660#M50564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="plain" name="code"&gt;#Build the where clause whereClause = "{0} in ('{1}')".format(fieldName, "','".join(values.split(';')))&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It's a little trickier than this because the each string value needs to be quoted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#Build the where clause values = values.split(";")&amp;nbsp; # split values into list values = ["'{0}'".format(v) for v in values] # add single quotes whereClause = "{0} IN ({1})".format(fieldName, ",".join(values))&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will generate a string that would work as a SQL expression like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Courier New;"&gt;FIELD1 IN ('R12351','R12352')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;UPDATE:&lt;/STRONG&gt;&lt;SPAN&gt; Mathew Coyle's solution also works. I didn't see that he was joining using the string "&amp;lt;single-quote&amp;gt;&amp;lt;comma&amp;gt;&amp;lt;single-quote&amp;gt;", ie "','".&amp;nbsp; Neat!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;He's right: Potato, tomato. I just can't resist showing off that most awesome of Python constructs, the "list comprehension", sorry.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 02:04:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649660#M50564</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-03-27T02:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: Multivalue query</title>
      <link>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649661#M50565</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It's my lazy way, but it still works. Though yours is more pythonic I would wager. Potato, tomato.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 02:44:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649661#M50565</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-03-27T02:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: Multivalue query</title>
      <link>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649662#M50566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Works great thank you to both of you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 13:27:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/multivalue-query/m-p/649662#M50566</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2013-03-27T13:27:39Z</dc:date>
    </item>
  </channel>
</rss>

