<?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: Setting Current version in SQL Server in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232236#M13184</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK, I now think I have gotten one step further with this. It appears the order of commands described in the Help topic &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//006z000000vn000000" rel="nofollow noopener noreferrer" target="_blank"&gt;"Editing versioned data in SQL Server using SQL"&lt;/A&gt;&lt;SPAN&gt; is &lt;/SPAN&gt;&lt;STRONG&gt;incorrect&lt;/STRONG&gt;&lt;SPAN&gt;, or that the ArcSDE stored procedure "SDE_getglobals" falsely doesn't allow you to set the current version when not in edit mode (at least in SQL Server, I don't know in other RDBMSs).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In addition, it appears any set version, only applies to the current active Transact SQL window, meaning you can't use it to change the way the view appears to the world outside SQL Server Management Studio (e.g. in Quantum GIS). Other applications accessing the Versioned View will only see the DEFAULT. Probably not entirely illogical, as setting the version as a kind of global for the entire database, would cause all users connected to the same Versioned Views to see the same version, and get confronted with subsequent changes. It needs to be user tied, or in this case limited to the context of the Transact SQL window.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It essentially means that edits against &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;&lt;STRONG&gt;a specific version&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; of a Versioned View is only supported straight in the Transact SQL command window, otherwise the ArcSDE C/Java API or ArcObjects is required, like for example the FDO Provider for ArcSDE in AutoCAD Map 3D does (uses C API) that does allow version switching on a user connection basis.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;According to the Help the order of the commands is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;1) Open a Transact-SQL query window and execute the create_version procedure to create a named version in which to perform your edits.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC sde.create_version 'sde.DEFAULT', 'myedits12111', 1, 2, 'version for my mv edits';&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;2) Set the version for the edit session to the child version you just created.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC sde.set_current_version 'myedits12111';&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;3) Start an edit session by executing the edit_version stored procedure and specifying 1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC sde.edit_version 'myedits12111', 1;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, I discovered the "sde.setcurrent_version" command fails and returns -1 for the version_id if NOT IN EDIT MODE already, even though the command is reported back as having run successfully.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This means you must run the text line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC sde.edit_version 'myedits12111', 1;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;before running:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC sde.set_current_version 'myedits12111';&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;E.g. if I enter (please note my ArcSDE is "dbo" owned, replace with "sde" if SDE owned):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC MyDatabaseName.dbo.set_current_version 'MyUser.MyVersionName'&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;than this fails...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I enter:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC MyDatabaseName.dbo.edit_version 'MyUser.MyVersionName', 1
EXEC MyDatabaseName.dbo.set_current_version 'MyUser.MyVersionName'
EXEC MyDatabaseName.dbo.edit_version 'MyUser.MyVersionName', 2&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with a start and end of an edit session, the command does run successfully. How do I know this? Well, first I entered some debugging code in the stored procedures for the "set_current_version" and "SDE_set_globals" and "SDE_get_globals". The results show the version_id is returned as a false -1 if not in edit mode, but the correct version_id for the "MyUser.MyVersionName" version if IN edit mode when setting the version.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In addition, I added a SELECT statement against the Versioned View in the same Transact SQL window, and the result showed the correct, NON-Default, version data with all the edits I did.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;E.g.:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC MyDatabaseName.dbo.edit_version 'MyUser.MyVersionName', 1
EXEC MyDatabaseName.dbo.set_current_version 'MyUser.MyVersionName'
EXEC MyDatabaseName.dbo.edit_version 'MyUser.MyVersionName', 2

SELECT * FROM MyDatabaseName.MyUser.MyDatasetName_VW&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;does show the proper &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Spatial Result&lt;/SPAN&gt;&lt;SPAN&gt; of the Versioned View in SQL Server Management Studio.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 11:45:06 GMT</pubDate>
    <dc:creator>MarcoBoeringa</dc:creator>
    <dc:date>2021-12-11T11:45:06Z</dc:date>
    <item>
      <title>Setting Current version in SQL Server</title>
      <link>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232230#M13178</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to set current version in SQL server using the stored procedure:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EXEC sde.set_current_version 'DBO.residence' &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But it doesn't seem to work because when I check my MV view, it seems to be referencing the DEFAULT version still.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Has anyone encountered this problem or know what the solution is?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Reuben&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Mar 2013 01:59:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232230#M13178</guid>
      <dc:creator>ReubenNwokeforo</dc:creator>
      <dc:date>2013-03-08T01:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Current version in SQL Server</title>
      <link>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232231#M13179</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Reuben,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have a DBO-schema geodatabase? If yes, then the stored procedure is owned by dbo, so try using the following syntax:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EXEC dbo.set_current_version '&amp;lt;version_name&amp;gt;'&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Mar 2013 17:14:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232231#M13179</guid>
      <dc:creator>MuneebAnsari</dc:creator>
      <dc:date>2013-03-08T17:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Current version in SQL Server</title>
      <link>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232232#M13180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello muneeb_ansari&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry for the late response. I have been away.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The Stored procedure is actually owned by SDE. But I have noticed the the default version is owned by SDE while all other versions are owned by the dbo. Would that be the issue and is there a way around it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Reuben&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Apr 2013 19:09:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232232#M13180</guid>
      <dc:creator>ReubenNwokeforo</dc:creator>
      <dc:date>2013-04-19T19:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Current version in SQL Server</title>
      <link>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232233#M13181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I am trying to set current version in SQL server using the stored procedure:&lt;BR /&gt;EXEC sde.set_current_version 'DBO.residence' &lt;BR /&gt;But it doesn't seem to work because when I check my MV view, it seems to be referencing the DEFAULT version still.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Has anyone encountered this problem or know what the solution is?&lt;/STRONG&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Reuben&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I recently ran into similar issues with SQL Server. I have a small test setup and test database using SQL Server Express with one versioned feature dataset with a few feature classes.. My instance is SQL Server 2012 Express SP1 upgraded from SQL Server 2008 R2 Express SP2, using ArcGIS 10.1 SP1. My database is DBO owned, and I can see the set_current_version stored procedure as dbo owned.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also tried to set the current version of a multiversioned view, but kept getting the DEFAULT (which is still at state 0). I ran the code snippet below (which comes straight from the versioned view code except for replacing "SELECT l.lineage_id" with "SELECT s.state_id"), that returns the state after running the set_current_version command (you can modify it to show lineage_id as well). It consistently returned state 0 after running the set_current_version command, while the version I tried to set has state 12. The set_current_version procedure ran successfully according to the message displayed in the SQL Server Management Studio status window.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Change dbo/sde in the snippet to either dbo or sde depending on who owns it:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SELECT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s.state_id&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; YOURDATABASENAME.dbo/sde.SDE_states s INNER LOOP JOIN&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; YOURDATABASENAME.dbo/sde.SDE_state_lineages l ON l.lineage_name = s.lineage_name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s.state_id = YOURDATABASENAME.dbo/sde.SDE_get_view_state() AND l.lineage_id &amp;lt;= s.state_id&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In my case, the version pointing to state 12 is also another user than dbo, who owns the default. The non-dbo owned version I tried to switch too from the default owned by dbo, is set "public". I haven't been able to figure this one out yet looking at things like the contents of the SDE_versions, SDE_states, SDE_states_lineages tables etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I must admit I did make an edit through Quantum GIS (QGIS) against the multiversioned view, before actually attempting to set a version through SQL Server Management Studio and the set_current_version command. But this should not necessarily cause issues, the multiversioned views are designed for this purpose. I did notice one issue though where ArcGIS did not recognize the proper extent of the total dataset (it did display the new polygon, but didn't properly zoom out to it). This was solved with another edit in ArcMap itself, which seems to have updated the layer's extent.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;QGIS also consistently shows state 0, the same if I look at the "Spatial results" window in SQL Server Management Studio.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Apr 2013 21:22:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232233#M13181</guid>
      <dc:creator>MarcoBoeringa</dc:creator>
      <dc:date>2013-04-19T21:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Current version in SQL Server</title>
      <link>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232234#M13182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hmm... I now found this thread mentioning at least one known relatively recent (2012) issue with the set_current_version stored procedure (or the other functions it calls), although that thread mentions it being related to DEFAULT:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/51244-Multi-versioned-Views-Not-seeing-data-in-the-A-amp-D-tables?highlight=set_current_version"&gt;http://forums.arcgis.com/threads/51244-Multi-versioned-Views-Not-seeing-data-in-the-A-amp-D-tables?highlight=set_current_version&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Still a real possibility there is an issue with my arcsde or geodatabase system tables, maybe related to the QGIS edit, but I don't see it at this point going through some of these tables (just a few records, since it is a small test database).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 19:25:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232234#M13182</guid>
      <dc:creator>MarcoBoeringa</dc:creator>
      <dc:date>2013-04-22T19:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Current version in SQL Server</title>
      <link>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232235#M13183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Don't know how to interpret this yet, but if I insert a:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-- BEGIN EDIT&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DECLARE @i int&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SET @i = @g_version_id&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SET @error_string = 'g_version_id: ' + (SELECT LTRIM(STR(@i,10)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RAISERROR (@error_string,16,-1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-- END EDIT&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;just before the last code lines in the set_current_version stored procedure (before the comment line "-- Finally, set the global info"), than the "g_version_id" comes up as -1. It should be 2 for the version I set if I look in the "dbo.SDE_versions" table...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 19:50:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232235#M13183</guid>
      <dc:creator>MarcoBoeringa</dc:creator>
      <dc:date>2013-04-22T19:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Current version in SQL Server</title>
      <link>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232236#M13184</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;OK, I now think I have gotten one step further with this. It appears the order of commands described in the Help topic &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//006z000000vn000000" rel="nofollow noopener noreferrer" target="_blank"&gt;"Editing versioned data in SQL Server using SQL"&lt;/A&gt;&lt;SPAN&gt; is &lt;/SPAN&gt;&lt;STRONG&gt;incorrect&lt;/STRONG&gt;&lt;SPAN&gt;, or that the ArcSDE stored procedure "SDE_getglobals" falsely doesn't allow you to set the current version when not in edit mode (at least in SQL Server, I don't know in other RDBMSs).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In addition, it appears any set version, only applies to the current active Transact SQL window, meaning you can't use it to change the way the view appears to the world outside SQL Server Management Studio (e.g. in Quantum GIS). Other applications accessing the Versioned View will only see the DEFAULT. Probably not entirely illogical, as setting the version as a kind of global for the entire database, would cause all users connected to the same Versioned Views to see the same version, and get confronted with subsequent changes. It needs to be user tied, or in this case limited to the context of the Transact SQL window.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It essentially means that edits against &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;&lt;STRONG&gt;a specific version&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; of a Versioned View is only supported straight in the Transact SQL command window, otherwise the ArcSDE C/Java API or ArcObjects is required, like for example the FDO Provider for ArcSDE in AutoCAD Map 3D does (uses C API) that does allow version switching on a user connection basis.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;According to the Help the order of the commands is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;1) Open a Transact-SQL query window and execute the create_version procedure to create a named version in which to perform your edits.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC sde.create_version 'sde.DEFAULT', 'myedits12111', 1, 2, 'version for my mv edits';&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;2) Set the version for the edit session to the child version you just created.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC sde.set_current_version 'myedits12111';&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;3) Start an edit session by executing the edit_version stored procedure and specifying 1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC sde.edit_version 'myedits12111', 1;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, I discovered the "sde.setcurrent_version" command fails and returns -1 for the version_id if NOT IN EDIT MODE already, even though the command is reported back as having run successfully.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This means you must run the text line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC sde.edit_version 'myedits12111', 1;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;before running:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC sde.set_current_version 'myedits12111';&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;E.g. if I enter (please note my ArcSDE is "dbo" owned, replace with "sde" if SDE owned):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC MyDatabaseName.dbo.set_current_version 'MyUser.MyVersionName'&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;than this fails...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I enter:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC MyDatabaseName.dbo.edit_version 'MyUser.MyVersionName', 1
EXEC MyDatabaseName.dbo.set_current_version 'MyUser.MyVersionName'
EXEC MyDatabaseName.dbo.edit_version 'MyUser.MyVersionName', 2&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with a start and end of an edit session, the command does run successfully. How do I know this? Well, first I entered some debugging code in the stored procedures for the "set_current_version" and "SDE_set_globals" and "SDE_get_globals". The results show the version_id is returned as a false -1 if not in edit mode, but the correct version_id for the "MyUser.MyVersionName" version if IN edit mode when setting the version.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In addition, I added a SELECT statement against the Versioned View in the same Transact SQL window, and the result showed the correct, NON-Default, version data with all the edits I did.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;E.g.:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;EXEC MyDatabaseName.dbo.edit_version 'MyUser.MyVersionName', 1
EXEC MyDatabaseName.dbo.set_current_version 'MyUser.MyVersionName'
EXEC MyDatabaseName.dbo.edit_version 'MyUser.MyVersionName', 2

SELECT * FROM MyDatabaseName.MyUser.MyDatasetName_VW&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;does show the proper &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Spatial Result&lt;/SPAN&gt;&lt;SPAN&gt; of the Versioned View in SQL Server Management Studio.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:45:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232236#M13184</guid>
      <dc:creator>MarcoBoeringa</dc:creator>
      <dc:date>2021-12-11T11:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Setting Current version in SQL Server</title>
      <link>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232237#M13185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Another observation:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had attempted to edit an EXISTING version by skipping the "dbo/sde.create_version" stored procedure and specifying an already existing version created in ArcMap that wasn't being edited by anyone else. It appears this is the primary cause of the issue, as adding a&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;EXEC MyDatabaseName.dbo.create_version 'MyUser.MyVersionName', 'MyEditVersion', 1, 2, 'version for my mv edits';&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;line in the first step, DOES allow you to run "dbo/sde.set_current_version" command with good results when pointing to the newly created version. It seems the "create_version" stored procedure sets some vital context for running the "set_current_version". In addition, ESRI seems to recommend to always create you own named version in a SQL edit session. From the Help:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;Create a named geodatabase version.&lt;BR /&gt;&lt;BR /&gt;If you are editing named versions (versions other than DEFAULT), always edit your own, separate version; multiple editors cannot edit the same named version using versioned views.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Apr 2013 09:32:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/setting-current-version-in-sql-server/m-p/232237#M13185</guid>
      <dc:creator>MarcoBoeringa</dc:creator>
      <dc:date>2013-04-24T09:32:10Z</dc:date>
    </item>
  </channel>
</rss>

