<?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: Help needed for definition query syntax to trim off leading 0s in text field. in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/help-needed-for-definition-query-syntax-to-trim/m-p/1112462#M8418</link>
    <description>&lt;P&gt;Hello Justine, I think the problem with your query is that it needs a SQL operator like (=, &amp;lt;, &amp;gt;,...). Your TRIM expression looks fine. Here's an example that'll return all rows with an empty OWNER_NAME after the leading and trailing white space is removed:&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;TRIM(BOTH ' ' FROM OWNER_NAME) = ''&lt;/LI-CODE&gt;&lt;P&gt;However, if you wanted to recalculate a field and remove the leading '0' you could use python like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def removezero(field):
    if (field[0] == "0"):
        return field[1:]
    else: 
        return(field)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Oct 2021 16:42:20 GMT</pubDate>
    <dc:creator>StevenTouzel</dc:creator>
    <dc:date>2021-10-29T16:42:20Z</dc:date>
    <item>
      <title>Help needed for definition query syntax to trim off leading 0s in text field.</title>
      <link>https://community.esri.com/t5/mapping-questions/help-needed-for-definition-query-syntax-to-trim/m-p/365701#M3906</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi. I keep getting errors - This is the syntax directly from ESRI:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE width="342"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="342"&gt;TRIM(BOTH | LEADING | TRAILING&amp;nbsp;trim_character&amp;nbsp;FROM&amp;nbsp;string_exp)&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I have tried:&amp;nbsp;&lt;/P&gt;&lt;TABLE width="342"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="342"&gt;&lt;P&gt;TRIM(LEADING '0' FROM "TRAIL_NO")&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE width="342"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="342"&gt;&lt;P&gt;TRIM(LEADING '0' FROM '0%')&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;both of these error with&amp;nbsp;&lt;/P&gt;&lt;TABLE width="147"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="147"&gt;Invalid SQL syntax [ORA-00920: invalid relational operator]&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I have also tried many other iterations and have received errors such as missing expression, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the correct syntax to remove leading 0s from a text field?&amp;nbsp; Please help, thanks!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also odd - one of the errors showed [STATE_ID = 27] and I do not have a state id field in my attribute table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2020 17:01:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/help-needed-for-definition-query-syntax-to-trim/m-p/365701#M3906</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-05-20T17:01:14Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed for definition query syntax to trim off leading 0s in text field.</title>
      <link>https://community.esri.com/t5/mapping-questions/help-needed-for-definition-query-syntax-to-trim/m-p/365702#M3907</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp;Justine&lt;/P&gt;&lt;P&gt;I&amp;nbsp;can only point you to the Help page,&amp;nbsp;and since you've tried that, I am going move this post over to the Mapping page where you will hopefully find an answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Bo&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/tag/sql query builder/tg-p"&gt;#sql query builder&lt;/A&gt;‌ &lt;A href="https://community.esri.com/t5/tag/sql functions/tg-p"&gt;#sql functions&lt;/A&gt;‌ &lt;A href="https://community.esri.com/t5/tag/sql statement/tg-p"&gt;#sql statement&lt;/A&gt;‌ &lt;A href="https://community.esri.com/t5/tag/trim/tg-p"&gt;#trim&lt;/A&gt;‌ &lt;A href="https://community.esri.com/t5/tag/layerquery/tg-p"&gt;#layerquery&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2020 17:48:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/help-needed-for-definition-query-syntax-to-trim/m-p/365702#M3907</guid>
      <dc:creator>Bo_King</dc:creator>
      <dc:date>2020-05-20T17:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed for definition query syntax to trim off leading 0s in text field.</title>
      <link>https://community.esri.com/t5/mapping-questions/help-needed-for-definition-query-syntax-to-trim/m-p/1089718#M8385</link>
      <description>&lt;P&gt;Good Afternoon,&lt;/P&gt;&lt;P&gt;Have you found a resolution to this?&amp;nbsp; I am only finding the same syntax documentation as you noted above.&amp;nbsp; I have not found any working examples of how to use TRIM as all instances of the question I've found in the Esri Community pages have been left unanswered.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 18:59:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/help-needed-for-definition-query-syntax-to-trim/m-p/1089718#M8385</guid>
      <dc:creator>MichaelTownshend</dc:creator>
      <dc:date>2021-08-17T18:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed for definition query syntax to trim off leading 0s in text field.</title>
      <link>https://community.esri.com/t5/mapping-questions/help-needed-for-definition-query-syntax-to-trim/m-p/1112462#M8418</link>
      <description>&lt;P&gt;Hello Justine, I think the problem with your query is that it needs a SQL operator like (=, &amp;lt;, &amp;gt;,...). Your TRIM expression looks fine. Here's an example that'll return all rows with an empty OWNER_NAME after the leading and trailing white space is removed:&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;TRIM(BOTH ' ' FROM OWNER_NAME) = ''&lt;/LI-CODE&gt;&lt;P&gt;However, if you wanted to recalculate a field and remove the leading '0' you could use python like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def removezero(field):
    if (field[0] == "0"):
        return field[1:]
    else: 
        return(field)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 16:42:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/help-needed-for-definition-query-syntax-to-trim/m-p/1112462#M8418</guid>
      <dc:creator>StevenTouzel</dc:creator>
      <dc:date>2021-10-29T16:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed for definition query syntax to trim off leading 0s in text field.</title>
      <link>https://community.esri.com/t5/mapping-questions/help-needed-for-definition-query-syntax-to-trim/m-p/1407612#M8568</link>
      <description>&lt;P&gt;Hello, I know this thread is 4 years old, but I wanted to help future users who found this using Google search like I did.&lt;/P&gt;&lt;P&gt;I found the correct ArcGIS SQL syntax to be&amp;nbsp;&lt;SPAN&gt;TRIM(LEADING '0' FROM TRAIL_NO) (no double quotes around the string expression variable). However, on my end, I still got an error after that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The Python lstrip function works to remove a leading character, but I assume if you're using SQL in the first place, you want to not use Python (which is slower). I got around this by definition querying/filtering the table first so that it doesn't iterate over unnecessary rows.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Finally, for my purpose, I ended up using the Ctrl + F (find and replace) feature instead. One needs to be careful with this function, but if it applies to your situation, it works *fast*.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2024 00:26:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/help-needed-for-definition-query-syntax-to-trim/m-p/1407612#M8568</guid>
      <dc:creator>JMCM</dc:creator>
      <dc:date>2024-04-13T00:26:09Z</dc:date>
    </item>
  </channel>
</rss>

