<?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: Using a list in SQL expression for FeatureClasstoFeatureClass in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087565#M62006</link>
    <description>&lt;P&gt;Check your SQL documentation for proper query syntax. You might try replacing the double quote with a single one, so you get:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;cab_id IN ('ESC-C02', 'ESC-C04', 'SDY-HUT')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Aug 2021 17:16:54 GMT</pubDate>
    <dc:creator>RandyBurton</dc:creator>
    <dc:date>2021-08-10T17:16:54Z</dc:date>
    <item>
      <title>Using a list in SQL expression for FeatureClasstoFeatureClass</title>
      <link>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087547#M62004</link>
      <description>&lt;P&gt;Hi there. I'm having an issue using a list in an SQL expression for FeatureClasstoFeatureClass export. Here is what I have so far. I'm working with a value list from user input.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;cab_list = arcpy.GetParameterAsText(0)
olt_list = cab_list.replace(";", ",")
olt_list = olt_list.split(',')
str_list = '"{}"'.format('", "'.join(olt_list))

arcpy.FeatureClassToFeatureClass_conversion(outcabs, scratch, 'Cabs_Boundary', f"cab_id IN ({str_list})")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The expression evaluates to&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;cab_id IN ("ESC-C02", "ESC-C04", "SDY-HUT")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I'm getting this error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 160144: An expected Field was not found or could not be retrieved properly.&lt;/P&gt;&lt;P&gt;I know that cab_id is the field name (not alias) so I'm guessing it has to be an issue with how I'm formatting the SQL clause. Any input is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 16:47:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087547#M62004</guid>
      <dc:creator>ChrisGAEG</dc:creator>
      <dc:date>2021-08-10T16:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using a list in SQL expression for FeatureClasstoFeatureClass</title>
      <link>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087559#M62005</link>
      <description>&lt;P&gt;Typically SQL clauses in python look something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;""""roadclass" = 2"""&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but in terms of a where in clause, try the expression in either map or pro and copy it into the script to see if it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If a SQL expression isn't working, then you can try the SearchCursor option to find the values that you need.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 17:13:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087559#M62005</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2021-08-10T17:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using a list in SQL expression for FeatureClasstoFeatureClass</title>
      <link>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087565#M62006</link>
      <description>&lt;P&gt;Check your SQL documentation for proper query syntax. You might try replacing the double quote with a single one, so you get:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;cab_id IN ('ESC-C02', 'ESC-C04', 'SDY-HUT')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 17:16:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087565#M62006</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-08-10T17:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using a list in SQL expression for FeatureClasstoFeatureClass</title>
      <link>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087567#M62007</link>
      <description>&lt;P&gt;How about:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;origString = 'a;b;c'
newList = origString.split(';')
#newList
#Out[16]: ['a', 'b', 'c']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That'll get you a list rather than the tuple which might be easier for the SQL statement.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 17:17:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087567#M62007</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-08-10T17:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using a list in SQL expression for FeatureClasstoFeatureClass</title>
      <link>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087611#M62010</link>
      <description>&lt;P&gt;Thanks for the input. I think this might be the case but I'm having a hard time formatting this line to use single quotes.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;str_list = '"{}"'.format('", "'.join(olt_list))&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 10 Aug 2021 18:35:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087611#M62010</guid>
      <dc:creator>ChrisGAEG</dc:creator>
      <dc:date>2021-08-10T18:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using a list in SQL expression for FeatureClasstoFeatureClass</title>
      <link>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087615#M62012</link>
      <description>&lt;P&gt;That did it. I just had to change that line to the inverse as follows -&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;str_list = "'{}'".format("','".join(olt_list))&lt;/LI-CODE&gt;&lt;P&gt;Thank you and everyone else for the tips!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 18:42:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-a-list-in-sql-expression-for/m-p/1087615#M62012</guid>
      <dc:creator>ChrisGAEG</dc:creator>
      <dc:date>2021-08-10T18:42:46Z</dc:date>
    </item>
  </channel>
</rss>

