<?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 Adding a Unique ID/ OBJECTID to a SQL Query Layer that uses GroupBy in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150366#M52313</link>
    <description>&lt;P&gt;I love using SQL views to summarize my data for use in Dashboards and Experience Builder. However, I keep running into the problem of not having a unique identifier for Pro to use. Here's an example query:&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;SELECT CONTENT_AREA, COUNT(CONTENT_AREA) AS Count
FROM SDE.Dataset
GROUP BY CONTENT_AREA&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That gives me a nice table that looks like this:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;CONTENT_AREA&lt;/TD&gt;&lt;TD width="50%"&gt;Count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Metric1&lt;/TD&gt;&lt;TD width="50%"&gt;99&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Metric2&lt;/TD&gt;&lt;TD width="50%"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Metric3&lt;/TD&gt;&lt;TD width="50%"&gt;73&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This query gives me the numbers I need, but Pro can't add it to the map because there is no unique identifier. In other queries that don't use the GROUP BY clause, I can use this trick:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;CAST(ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS INT) AS OBJECTID&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... but this doesn't work in Pro unless I include OBJECTID in the GROUP BY clause.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Mar 2022 20:29:26 GMT</pubDate>
    <dc:creator>AmyRoust</dc:creator>
    <dc:date>2022-03-03T20:29:26Z</dc:date>
    <item>
      <title>Adding a Unique ID/ OBJECTID to a SQL Query Layer that uses GroupBy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150366#M52313</link>
      <description>&lt;P&gt;I love using SQL views to summarize my data for use in Dashboards and Experience Builder. However, I keep running into the problem of not having a unique identifier for Pro to use. Here's an example query:&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;SELECT CONTENT_AREA, COUNT(CONTENT_AREA) AS Count
FROM SDE.Dataset
GROUP BY CONTENT_AREA&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That gives me a nice table that looks like this:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;CONTENT_AREA&lt;/TD&gt;&lt;TD width="50%"&gt;Count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Metric1&lt;/TD&gt;&lt;TD width="50%"&gt;99&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Metric2&lt;/TD&gt;&lt;TD width="50%"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Metric3&lt;/TD&gt;&lt;TD width="50%"&gt;73&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This query gives me the numbers I need, but Pro can't add it to the map because there is no unique identifier. In other queries that don't use the GROUP BY clause, I can use this trick:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;CAST(ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS INT) AS OBJECTID&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... but this doesn't work in Pro unless I include OBJECTID in the GROUP BY clause.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 20:29:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150366#M52313</guid>
      <dc:creator>AmyRoust</dc:creator>
      <dc:date>2022-03-03T20:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Unique ID/ OBJECTID to a SQL Query Layer that uses GroupBy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150393#M52321</link>
      <description>&lt;P&gt;I think this will work... my field is called TxtTest though&lt;/P&gt;&lt;P&gt;This was written is SQL Server but should work&amp;nbsp; the same:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KimGarbade_1-1646341566538.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35525iB2F465A93E69065A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KimGarbade_1-1646341566538.png" alt="KimGarbade_1-1646341566538.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 21:06:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150393#M52321</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-03-03T21:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Unique ID/ OBJECTID to a SQL Query Layer that uses GroupBy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150439#M52329</link>
      <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/119500"&gt;@KimberlyGarbade&lt;/a&gt;! That partially worked, but didn't get me all the way across the finish line. In SSMS, the query works, but when I try to save it as a view, I get this error message:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AmyRoust_0-1646343945778.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35540i6D4F00325E390CB8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AmyRoust_0-1646343945778.png" alt="AmyRoust_0-1646343945778.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I saved anyway and tried to add the table to Pro, but got this message when I tried to open the attribute table:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AmyRoust_1-1646344046993.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35541i48109424559FDA07/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AmyRoust_1-1646344046993.png" alt="AmyRoust_1-1646344046993.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Then I tried adding the actual query as a query layer in Pro. That worked - it added to the map and I was able to open the attribute table and view its contents. But, when I tried to publish a REST service to our stand-alone ArcGIS Server, it gave me several unhelpful errors:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AmyRoust_2-1646344732591.png" style="width: 692px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35543i50839A9EE3E2975C/image-dimensions/692x230?v=v2" width="692" height="230" role="button" title="AmyRoust_2-1646344732591.png" alt="AmyRoust_2-1646344732591.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 22:00:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150439#M52329</guid>
      <dc:creator>AmyRoust</dc:creator>
      <dc:date>2022-03-03T22:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Unique ID/ OBJECTID to a SQL Query Layer that uses GroupBy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150473#M52335</link>
      <description>&lt;P&gt;Hmmm...Sorry this is going to be long.&lt;/P&gt;&lt;P&gt;When I tested in my home environment I saw different messages and worked around them until it worked.&amp;nbsp; I realize our environments are different, but maybe my experience will give you a clue.&lt;/P&gt;&lt;P&gt;I will walk you through what I did (keeping in mind we're almost certainly on different versions of everything)&lt;/P&gt;&lt;P&gt;I created the View in SSMS just in a query window and it worked for me:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KimGarbade_0-1646345822152.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35545i153A7DCD5E97B6CB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KimGarbade_0-1646345822152.png" alt="KimGarbade_0-1646345822152.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KimGarbade_1-1646345909319.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35546i3AB3D1C8895A23B0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KimGarbade_1-1646345909319.png" alt="KimGarbade_1-1646345909319.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Adding this view to my map in Pro did not work initially, returning this error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KimGarbade_2-1646347184900.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35547i4DE1ACDD7972015A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KimGarbade_2-1646347184900.png" alt="KimGarbade_2-1646347184900.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;To fix this I opened the Properties &amp;gt; Source for the view in ArcGIS Pro and edited the SQL Query it was using to simply remove the double quotes it had put around "COUNT" for some reason&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KimGarbade_3-1646347336675.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35548i8FC7207287FC4787/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KimGarbade_3-1646347336675.png" alt="KimGarbade_3-1646347336675.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Once I did that the view table would open in Pro, but oddly it added an ESRI_OID field which in effect is what you wanted all along, and makes the "UniqueID" field I calculated in the view obsolete:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KimGarbade_4-1646347506942.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35549i0F01B3B66264530D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KimGarbade_4-1646347506942.png" alt="KimGarbade_4-1646347506942.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So finally I Altered my view by removed the "Row_Number() Over(ORDER BY TxtTest asc) as UniqueID," part ,re-added it to my map in Pro, and edited the query to remove the double quotes around "COUNT" and got this when viewing the view table in Pro&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KimGarbade_5-1646347926242.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35550i2347E8C0C3BFDD48/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KimGarbade_5-1646347926242.png" alt="KimGarbade_5-1646347926242.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 22:56:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150473#M52335</guid>
      <dc:creator>KimberlyGarbade</dc:creator>
      <dc:date>2022-03-03T22:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Unique ID/ OBJECTID to a SQL Query Layer that uses GroupBy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150535#M52354</link>
      <description>&lt;P&gt;Hi, one option to include other columns is to replace the GROUP BY clause with an SQL expression with a Sub Query or nested query. Annex I send an example adapted to your case.&lt;/P&gt;&lt;P&gt;SELECT DISTINCT OBJECTID, CONTENT_AREA, (SELECT COUNT(CONTENT_AREA)&lt;BR /&gt;FROM SDE.Dataset AS SDE_Dataset_B&lt;BR /&gt;WHERE SDE_Dataset_B = SDE_Dataset_A) AS Count&lt;BR /&gt;FROM SDE.Dataset AS SDE_Dataset_A&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 03:26:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150535#M52354</guid>
      <dc:creator>Reinaldo_Cartagena</dc:creator>
      <dc:date>2022-03-04T03:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Unique ID/ OBJECTID to a SQL Query Layer that uses GroupBy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150656#M52366</link>
      <description>&lt;P&gt;We had very similar experiences,&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/119500"&gt;@KimberlyGarbade&lt;/a&gt;. (I laughed when you made the comment about the mysterious ESRI_ID field appearing. What the heck??) The only thing I can't replicate in your second answer is in the last step. I cannot find a way to add the modified view to Pro if it doesn't have the UniqueID field.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fortunately, between your tips and the suggestion from&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/469823"&gt;@Reinaldo_Cartagena&lt;/a&gt;,&amp;nbsp;I thought up a new solution. I saved my view without a unique id, and then created a second view where I joined my first view to a master table that contains a single list of all CONTENT_AREA values. In that second query, I added the OID from the master table and got what I needed.&lt;/P&gt;&lt;P&gt;I have a hunch that Reinaldo's solution is more elegant than what I did, but I couldn't quite parse out his example in my own mind. (I've never been good at nested queries.)&lt;/P&gt;&lt;P&gt;Appreciate the help!&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 14:36:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1150656#M52366</guid>
      <dc:creator>AmyRoust</dc:creator>
      <dc:date>2022-03-04T14:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Unique ID/ OBJECTID to a SQL Query Layer that uses GroupBy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1337422#M73955</link>
      <description>&lt;P&gt;Your ROW_NUMBER function is missing one key thing... that is the ISNULL () function needs to be added in front of ROW_NUMBER.&lt;/P&gt;&lt;P&gt;SELECT ISNULL(CAST(ROW_NUMBER() OVER&lt;/P&gt;&lt;P&gt;&amp;nbsp; (&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; ORDER BY [field]&lt;/P&gt;&lt;P&gt;&amp;nbsp; ) AS int), &lt;EM&gt;replacement_value&lt;/EM&gt;&amp;nbsp;--this value can be 0, since it is highly unlikely that your ID will return a Not NULL value since you are using the ROW_NUMBER function--) AS [ID]&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Correction to my previous comment about the ISNULL replacement value:&lt;/STRONG&gt;&lt;/EM&gt; the &lt;EM&gt;&lt;STRONG&gt;replacement_value&lt;/STRONG&gt;&lt;/EM&gt; for the ISNULL function returns the given value if the expression returns a NULL value.&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/sql/t-sql/functions/isnull-transact-sql?view=sql-server-ver16" target="_blank"&gt;ISNULL (Transact-SQL) - SQL Server | Microsoft Learn&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You should NOT include OBJECTID from the parent table in your views (see article below).&amp;nbsp; That is why you are seeing the ESRI_OID in Pro when using "Query Layer".&amp;nbsp; Esri needs a unique integer value that is not null.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/manage-sql-server/views-in-geodatabase.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/manage-sql-server/views-in-geodatabase.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 15:09:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1337422#M73955</guid>
      <dc:creator>DonSjoboen</dc:creator>
      <dc:date>2023-10-31T15:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Unique ID/ OBJECTID to a SQL Query Layer that uses GroupBy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1342945#M74565</link>
      <description>&lt;P&gt;Thank you DonSjoboen. The addition of isNull did the trick for me to create a recognized ObjectID value in my Database View.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 20:55:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1342945#M74565</guid>
      <dc:creator>CaseyWilson1</dc:creator>
      <dc:date>2023-10-27T20:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a Unique ID/ OBJECTID to a SQL Query Layer that uses GroupBy</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1343888#M74680</link>
      <description>&lt;P&gt;Glad it worked out for you.&amp;nbsp; I amended my previous reply and added the correct description/reason for the ISNULL replacement_value part of the function, along with SQL Server documentation.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 15:11:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/adding-a-unique-id-objectid-to-a-sql-query-layer/m-p/1343888#M74680</guid>
      <dc:creator>DonSjoboen</dc:creator>
      <dc:date>2023-10-31T15:11:43Z</dc:date>
    </item>
  </channel>
</rss>

