<?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 SQL script to edit a named version in SQL Server Manager? in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/using-sql-script-to-edit-a-named-version-in-sql/m-p/1333391#M6773</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to figure out how to edit a named version using a sql script and I am not sure how to go about it. I can pull the named version information, but I am not sure how to update the information in the table.&lt;/P&gt;&lt;P&gt;Here is what I have thus far.&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;EXEC [Database].sde.edit_version 2, 1; -- opens edit session on version
EXEC [Database].sde.set_current_version 2; -- Sets version to access
BEGIN TRY
BEGIN TRANSACTION [Tran1]

MERGE [Database].[Featureclass_evw] as TargetTable
USING [Server].[Database].[dbo].[Table] as SourceTable
ON TargetTable.[MatchingColumn] = SourceTable.[MatchingColumn]
WHEN MATCHED THEN
  UPDATE SET TargetTable.[ColumnA] = SourceTable.[ColumnB]
  ;

COMMIT TRANSACTION [Tran1] -- if successful will commit the transaction
END TRY
BEGIN CATCH -- if error occurs, will rollback the transaction
    ROLLBACK TRANSACTION [Tran1]
END CATCH
EXEC [Database].sde.edit_version 2, 2; -- ends the edit session&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried this option below.&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;EXEC [Database].sde.edit_version 2, 1; -- opens edit session on version
EXEC [Database].sde.set_current_version 2; -- Sets version to access
BEGIN TRY
BEGIN TRANSACTION [Tran1]

UPDATE [sdeowner].[Featureclass_evw]
SET [Field] = (
SELECT A.[Field]
FROM [Server].[Database].[dbo].[Table] AS A
JOIN [SDEOwner].[Featureclass_evw] ON [SDEOwner].[Featureclass_evw].[Field] = A.[Field]
WHERE EXISTS ( 
	SELECT 1
	FROM [Server].[Database].[dbo].[Table] AS A
	WHERE [Field] = [SDEOwner].[Featureclass_evw].[Field]
	)
)
COMMIT TRANSACTION [Tran1] -- if successful will commit the transaction
END TRY
BEGIN CATCH -- if error occurs, will rollback the transaction
    ROLLBACK TRANSACTION [Tran1]
END CATCH
EXEC [Database].sde.edit_version 2, 2; -- ends the edit session&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot seem to update the values based on these sql queries so I am stuck for the time being. Any help on this would be greatly appreciated.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2023 15:04:01 GMT</pubDate>
    <dc:creator>RPGIS</dc:creator>
    <dc:date>2023-09-28T15:04:01Z</dc:date>
    <item>
      <title>Using SQL script to edit a named version in SQL Server Manager?</title>
      <link>https://community.esri.com/t5/developers-questions/using-sql-script-to-edit-a-named-version-in-sql/m-p/1333391#M6773</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to figure out how to edit a named version using a sql script and I am not sure how to go about it. I can pull the named version information, but I am not sure how to update the information in the table.&lt;/P&gt;&lt;P&gt;Here is what I have thus far.&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;EXEC [Database].sde.edit_version 2, 1; -- opens edit session on version
EXEC [Database].sde.set_current_version 2; -- Sets version to access
BEGIN TRY
BEGIN TRANSACTION [Tran1]

MERGE [Database].[Featureclass_evw] as TargetTable
USING [Server].[Database].[dbo].[Table] as SourceTable
ON TargetTable.[MatchingColumn] = SourceTable.[MatchingColumn]
WHEN MATCHED THEN
  UPDATE SET TargetTable.[ColumnA] = SourceTable.[ColumnB]
  ;

COMMIT TRANSACTION [Tran1] -- if successful will commit the transaction
END TRY
BEGIN CATCH -- if error occurs, will rollback the transaction
    ROLLBACK TRANSACTION [Tran1]
END CATCH
EXEC [Database].sde.edit_version 2, 2; -- ends the edit session&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried this option below.&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;EXEC [Database].sde.edit_version 2, 1; -- opens edit session on version
EXEC [Database].sde.set_current_version 2; -- Sets version to access
BEGIN TRY
BEGIN TRANSACTION [Tran1]

UPDATE [sdeowner].[Featureclass_evw]
SET [Field] = (
SELECT A.[Field]
FROM [Server].[Database].[dbo].[Table] AS A
JOIN [SDEOwner].[Featureclass_evw] ON [SDEOwner].[Featureclass_evw].[Field] = A.[Field]
WHERE EXISTS ( 
	SELECT 1
	FROM [Server].[Database].[dbo].[Table] AS A
	WHERE [Field] = [SDEOwner].[Featureclass_evw].[Field]
	)
)
COMMIT TRANSACTION [Tran1] -- if successful will commit the transaction
END TRY
BEGIN CATCH -- if error occurs, will rollback the transaction
    ROLLBACK TRANSACTION [Tran1]
END CATCH
EXEC [Database].sde.edit_version 2, 2; -- ends the edit session&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot seem to update the values based on these sql queries so I am stuck for the time being. Any help on this would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 15:04:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/using-sql-script-to-edit-a-named-version-in-sql/m-p/1333391#M6773</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2023-09-28T15:04:01Z</dc:date>
    </item>
  </channel>
</rss>

