Using SQL script to edit a named version in SQL Server Manager?

202
0
09-28-2023 08:04 AM
RPGIS
by
Occasional Contributor III

Hi,

 

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.

Here is what I have thus far.

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

 

I have also tried this option below.

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

 

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.

0 Kudos
0 Replies