<?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 Python value variable in SQL expression FeatureLayer.query(where = &amp;quot;attributeName = 'StringValue'&amp;quot; ) in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1211928#M7738</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to insert a variable where ClientName is written:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Fl_Filtered = FeatureLayer.query(where = "client = 'clientName'")&lt;/LI-CODE&gt;&lt;P&gt;I tried this without success:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;querytxt = 'where = "KundeName = ' + "'" + ""'%s'"" %kundeNameWhereFilter + "'" + '"'
Print(querytxt)
Fl_Filtered = FeatureLayer.query(querytxt)&lt;/LI-CODE&gt;&lt;P&gt;The print ist returns the right String but the query returns an Error code: 400&lt;/P&gt;&lt;P&gt;&amp;nbsp;Anyone knows how could be the solution?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 13 Sep 2022 10:11:52 GMT</pubDate>
    <dc:creator>AngelRomoSandoval</dc:creator>
    <dc:date>2022-09-13T10:11:52Z</dc:date>
    <item>
      <title>Python value variable in SQL expression FeatureLayer.query(where = "attributeName = 'StringValue'" )</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1211928#M7738</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to insert a variable where ClientName is written:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Fl_Filtered = FeatureLayer.query(where = "client = 'clientName'")&lt;/LI-CODE&gt;&lt;P&gt;I tried this without success:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;querytxt = 'where = "KundeName = ' + "'" + ""'%s'"" %kundeNameWhereFilter + "'" + '"'
Print(querytxt)
Fl_Filtered = FeatureLayer.query(querytxt)&lt;/LI-CODE&gt;&lt;P&gt;The print ist returns the right String but the query returns an Error code: 400&lt;/P&gt;&lt;P&gt;&amp;nbsp;Anyone knows how could be the solution?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 10:11:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1211928#M7738</guid>
      <dc:creator>AngelRomoSandoval</dc:creator>
      <dc:date>2022-09-13T10:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Python value variable in SQL expression FeatureLayer.query(where = "attributeName = 'StringValue'" )</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1211930#M7739</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/545315"&gt;@AngelRomoSandoval&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I like to use the string format, there are various options, see &lt;A href="https://www.w3schools.com/python/ref_string_format.asp" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;The example below uses numbered indexes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;## example 1
client_name = "My Clients Name"
Fl_Filtered = FeatureLayer.query(where = "client = '{0}'".format(client_name)
### DO SOMETHING WITH THE CLIENT

## example 2
client_list = ["Client 1", "Client 2", "Client 3"]

for client_name in client_list:
    Fl_Filtered = FeatureLayer.query(where = "client = '{0}'".format(client_name)
### DO SOMETHING WITH EACH INDIVIDUAL CLIENT&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;also, how are you accessing the Feature Layer?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis import GIS

agol = GIS("home")

feature_service = agol.content.get("***ITEM_ID***")

feature_layer = feature_service.layers[0] # where 0 is the index of the first layer in the featire service

client_name = "My Clients Name"
Fl_Filtered = feature_layer.query(where = "client = '{0}'".format(client_name)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 13 Sep 2022 10:26:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1211930#M7739</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2022-09-13T10:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Python value variable in SQL expression FeatureLayer.query(where = "attributeName = 'StringValue'" )</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1211937#M7740</link>
      <description>&lt;P&gt;Yes, I access with the Item Id.&amp;nbsp; Thank you for all the examples!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 11:22:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1211937#M7740</guid>
      <dc:creator>AngelRomoSandoval</dc:creator>
      <dc:date>2022-09-13T11:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Python value variable in SQL expression FeatureLayer.query(where = "attributeName = 'StringValue'" )</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1213811#M7769</link>
      <description>&lt;P&gt;Be careful when doing this if the variable value is coming from an outside source.&amp;nbsp; A SQL injection attack could be done.&amp;nbsp; &amp;nbsp;Before deploying the simple solution read a bit more about SQL injection attacks and how to defend your code against them.&amp;nbsp; Here is one source,&amp;nbsp;&lt;A href="https://realpython.com/prevent-python-sql-injection/," target="_blank"&gt;https://realpython.com/prevent-python-sql-injection/,&lt;/A&gt;&amp;nbsp;many others to consult.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2022 14:14:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1213811#M7769</guid>
      <dc:creator>DavidAnderson_1701</dc:creator>
      <dc:date>2022-09-19T14:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Python value variable in SQL expression FeatureLayer.query(where = "attributeName = 'StringValue'" )</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1218855#M7851</link>
      <description>&lt;P&gt;There is already a function to validate the SQL string built in to the API. Very straightforward.&lt;/P&gt;&lt;P&gt;&lt;A title="Validate SQL" href="https://developers.arcgis.com/python/api-reference/arcgis.features.html#arcgis.features.FeatureLayer.validate_sql" target="_self"&gt;https://developers.arcgis.com/python/api-reference/arcgis.features.html#arcgis.features.FeatureLayer.validate_sql&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2022 23:01:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1218855#M7851</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2022-10-04T23:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python value variable in SQL expression FeatureLayer.query(where = "attributeName = 'StringValue'" )</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1230808#M7993</link>
      <description>&lt;P&gt;Thank you for the info, no, it comes not from an external source. I will keep it in mind.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2022 09:08:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-value-variable-in-sql-expression/m-p/1230808#M7993</guid>
      <dc:creator>AngelRomoSandoval</dc:creator>
      <dc:date>2022-11-11T09:08:34Z</dc:date>
    </item>
  </channel>
</rss>

