<?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: EXTRACT(YEAR FROM...) query not working on SDE database in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/extract-year-from-query-not-working-on-sde/m-p/491569#M27932</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is because ArcGIS uses the database syntax to handle where clauses.&amp;nbsp; Every database is slightly different with different functions.&amp;nbsp; Something that works in Oracle may not working SQL Server.&amp;nbsp; Something in a File GDB may not work in Postgres.&amp;nbsp; And so on.&amp;nbsp; The document you reference refers to this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;STRONG style="color: #595959; background-color: #ffffff; font-weight: 500;"&gt;Other databases&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #595959; background-color: #ffffff; font-weight: 300;"&gt;Please consult the database's function documentation and syntax.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #595959; background-color: #ffffff; font-weight: 300;"&gt;For example, SQL server uses the same DATEPART function as personal geodatabases, but with slightly different syntax:&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So you need to look up the proper way to query a year for your database type.&amp;nbsp; Which database are you working with?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 09 Apr 2018 13:44:31 GMT</pubDate>
    <dc:creator>KevinDunlop</dc:creator>
    <dc:date>2018-04-09T13:44:31Z</dc:date>
    <item>
      <title>EXTRACT(YEAR FROM...) query not working on SDE database</title>
      <link>https://community.esri.com/t5/data-management-questions/extract-year-from-query-not-working-on-sde/m-p/491568#M27931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For some reason this query&amp;nbsp;works on FGDB but not SDE geodatabases. Is that by design? When I use select by attributes and type this query:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EXTRACT(YEAR FROM MyDateField) = 2015&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will work on a file geodatabase. When I try the same query with an SDE geodatabase, I get the error:&lt;/P&gt;&lt;P&gt;"There was an error executing the query. Invalid SQL syntax [[Microsoft][ODBC Driver 13 for SQL Server][SQL Server] Incorrect syntax near the keyword 'FROM'.][mydata.dbo.database]."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried rewriting the query in these ways but all come back with the same error:&lt;/P&gt;&lt;P&gt;EXTRACT(YEAR FROM "MyDateField") = 2015&lt;/P&gt;&lt;P&gt;EXTRACT(YEAR FROM MyDateField) = '2015'&lt;/P&gt;&lt;P&gt;EXTRACT(YEAR FROM [MyDateField]) = 2015&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The last thing I tried was the&amp;nbsp;DatePart function. This appears to work on SDE geodatabases:&lt;/P&gt;&lt;P&gt;DatePart("yyyy", MyDateField) = 2015&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am confused as to why this one works but not the EXTRACT one, especially because DatePart looks like it's meant for personal geodatabases:&amp;nbsp;&lt;A class="link-titled" href="https://support.esri.com/en/technical-article/000011531" title="https://support.esri.com/en/technical-article/000011531"&gt;How To: Search for specific parts of a date stored in a Date-Time field&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additionally, when building a query to use as a filter in Javascript API, the EXTRACT(YEAR FROM "MyDateField") = 2015 works on the SDE data and the DatePart does not. You'd think that one of these types of queries would work in all cases...frustrating.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Apr 2018 12:19:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/extract-year-from-query-not-working-on-sde/m-p/491568#M27931</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2018-04-09T12:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: EXTRACT(YEAR FROM...) query not working on SDE database</title>
      <link>https://community.esri.com/t5/data-management-questions/extract-year-from-query-not-working-on-sde/m-p/491569#M27932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is because ArcGIS uses the database syntax to handle where clauses.&amp;nbsp; Every database is slightly different with different functions.&amp;nbsp; Something that works in Oracle may not working SQL Server.&amp;nbsp; Something in a File GDB may not work in Postgres.&amp;nbsp; And so on.&amp;nbsp; The document you reference refers to this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;STRONG style="color: #595959; background-color: #ffffff; font-weight: 500;"&gt;Other databases&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #595959; background-color: #ffffff; font-weight: 300;"&gt;Please consult the database's function documentation and syntax.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #595959; background-color: #ffffff; font-weight: 300;"&gt;For example, SQL server uses the same DATEPART function as personal geodatabases, but with slightly different syntax:&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So you need to look up the proper way to query a year for your database type.&amp;nbsp; Which database are you working with?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Apr 2018 13:44:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/extract-year-from-query-not-working-on-sde/m-p/491569#M27932</guid>
      <dc:creator>KevinDunlop</dc:creator>
      <dc:date>2018-04-09T13:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: EXTRACT(YEAR FROM...) query not working on SDE database</title>
      <link>https://community.esri.com/t5/data-management-questions/extract-year-from-query-not-working-on-sde/m-p/491570#M27933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah, that would explain why DatePart worked well for my SDE geodatabase in ArcMap (it's an SQL Server database), although I would say the documentation is not particularly correct as I was able to get DatePart to work on my database without the "special" SQL Server syntax they have listed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Still does not explain why the use case switches when trying to perform this query in the Javascript API though. EXTRACT(YEAR FROM...) works on the database while DatePart does not inside the Javascript API.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Apr 2018 14:16:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/extract-year-from-query-not-working-on-sde/m-p/491570#M27933</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2018-04-09T14:16:01Z</dc:date>
    </item>
  </channel>
</rss>

