indxlogic

Untitled

May 30th, 2023
2,818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.11 KB | None | 0 0
  1. --Define the Selection criteria
  2. DECLARE @pathStart varchar(50);
  3. SELECT @pathStart = 'http://nacc-az-smpp:9091/v1/';
  4.  
  5. --Create a TMP table using the DOCID, existing moniker, and the new moniker
  6. --NOTE: Test without the "INTO TMP_Moniker" until you are sure the "new" moniker is correct
  7. SELECT DOCID, MONIKER as old, Replace(MONIKER,'/nacc-az-smpp/','/nacc-az-indx01/') as new INTO TMP_Moniker FROM EXTREFERENCES WHERE SUBSTRING(MONIKER,1,len(@pathStart)) = @pathStart;
  8.  
  9. --Join EXTREFERENCES to TMP_Moniker on the DOCID and update with the "new" value
  10. UPDATE EXTREFERENCES
  11. SET MONIKER = tmp.new
  12. FROM EXTREFERENCES
  13. INNER JOIN TMP_Moniker tmp ON EXTREFERENCES.DOCID = tmp.DOCID;
  14.  
  15. /*
  16. NOTES:
  17. - If for any reason this needs to be reverted, it is very easy to do so by running the update again with the "old" column.
  18. - This query only affects a subset of records. It protects against an accidental replacement in unrelated records
  19. - Using the variable for the selection and SUBSTRING is much more effcient than using LIKE
  20. - If the tables are very large, you can create an index on the tmp table on the DOCID column
  21. */
  22.  
Advertisement