<?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 Using .format in arcpy.SelectByAttributes Where Clause in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-format-in-arcpy-selectbyattributes-where/m-p/74527#M6096</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to pass an integer variable into the where clause of the arcpy.SelectByAttribute tool on an sde feature class to select a record from a "Long" field type.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;siteNumber = 324850
SQL_Query = 'NUMBER_ID = {0}'.format(siteNumber)
arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", SQL_Query)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This does not return any selected records.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I hard code the query in:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SelectLayerByAttribute_management("lyr2", "NEW_SELECTION", 'NUMBER_ID = 391530')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then it will work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I print out my SQL_Query variable, I get &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;NUMBER_ID = 324850&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;SQL_Query = "\"NUMBER_ID\" = {0}".format(siteNumber)
SQL_Query = "\"NUMBER_ID\" = '{0}'".format(siteNumber)
SQL_Query = '[NUMBER_ID] = {0}'.format(siteNumber)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and a few other methods, and I still can't get it to return a selected record.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 22:53:33 GMT</pubDate>
    <dc:creator>MikeMacRae</dc:creator>
    <dc:date>2021-12-10T22:53:33Z</dc:date>
    <item>
      <title>Using .format in arcpy.SelectByAttributes Where Clause</title>
      <link>https://community.esri.com/t5/python-questions/using-format-in-arcpy-selectbyattributes-where/m-p/74527#M6096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to pass an integer variable into the where clause of the arcpy.SelectByAttribute tool on an sde feature class to select a record from a "Long" field type.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;siteNumber = 324850
SQL_Query = 'NUMBER_ID = {0}'.format(siteNumber)
arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", SQL_Query)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This does not return any selected records.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I hard code the query in:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SelectLayerByAttribute_management("lyr2", "NEW_SELECTION", 'NUMBER_ID = 391530')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then it will work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I print out my SQL_Query variable, I get &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;NUMBER_ID = 324850&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;SQL_Query = "\"NUMBER_ID\" = {0}".format(siteNumber)
SQL_Query = "\"NUMBER_ID\" = '{0}'".format(siteNumber)
SQL_Query = '[NUMBER_ID] = {0}'.format(siteNumber)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and a few other methods, and I still can't get it to return a selected record.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:53:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-format-in-arcpy-selectbyattributes-where/m-p/74527#M6096</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-12-10T22:53:33Z</dc:date>
    </item>
  </channel>
</rss>

