DECLARE @OldName nvarchar (100)
DECLARE @newName nvarchar (100)

-- Replace the variables <OLDSERVERNAME> and <NEWSERVERNAME> below with the actual names of the old and new PME servers. 
-- Use all upper-case letters for the names. Do not remove the single quotes " ' ".

SET @oldName = '<OLD_PME_SERVERNAME>'
SET @newName = '<NEW_PME_SERVERNAME>'

-- Replace the variable <ARCHIVEDATABASENAME> below with the actual name of the archive database, e.g. "ION_Data_Archive13_10_25_03_16".
USE <ArchiveDatabaseName>


-- update Source table

UPDATE [Source]
SET Name = 'LOGINSERTER.' + @newName
WHERE Name = 'LOGINSERTER.' + @oldName

UPDATE [Source]
SET Name = 'QUERYSERVER.' + @newName
WHERE Name = 'QUERYSERVER.' + @oldName

--UPDATE [Source]
--SET Name = 'VIP.' + @newName
--WHERE Name = 'VIP.' + @oldName

IF COL_LENGTH('Source','DisplayName') IS NOT NULL
BEGIN

	EXEC ('UPDATE [Source] SET DisplayName = ' + 'LOGINSERTER.' + @newName + ' WHERE DisplayName = ' + 'LOGINSERTER.' + @oldName)

	EXEC ('UPDATE [Source] SET DisplayName = ' + 'QUERYSERVER.' + @newName + ' WHERE DisplayName = ' + 'QUERYSERVER.' + @oldName)

	-- EXEC ('UPDATE [Source] SET DisplayName = ' + 'VIP.' + @newName + ' WHERE DisplayName = ' + 'VIP.' + @oldName)

END