Menu

Search

InstantASP Support

Help & Support


Performing a Global Search & Replace Within InstantKB Articles


Common Questions

It's often helpful to be able to replace specific text within all your articles within InstantKB. For example maybe you want to change a product name or URL within all your articles. 

Unfortunately we don't offer a global find and replace feature currently within our interface as we first want to ensure we have versioning and roll back capabilities in case a mistake is made during a global find and replace. Global find & replace is on our road-map. 

If your comfortable with basic TSQL and are able to access your InstantKB database you can easily perform a global find and replace right now using the TSQL script below. 

TSQL For Global Find & Replace Within Articles

To use this script you'll need to connect to your InstantKB database within SQL Server Management Studio or similar tool and execute the script against your InstantKB database. You will need to update the @searchFor and @replaceWith variables with your real search and replace values. 

Before running this find & replace script we would strongly suggest you take a fresh back-up of your database. You can't undo changes made via this script. 

 -- ABOUT
-- this script will loop through all articles and replace all
--  instances of the text supplied within the @searchFor variable
-- with the value specified within the @replaceWith variable
-- replace the values below with your real search & replace values
-- this will only replace text within the article body - article titles will not be changed

-- NOTES
-- It's very important you take a back-up of your database before running this script
-- any changes made via this script cannot be easily reserved
-- Please ensure you are very specific with your search text

DECLARE @searchFor  nvarchar(255)
SET @searchFor = 'https://www.olddomain.com/';
DECLARE @replaceWith  nvarchar(255)
SET @replaceWith = 'https://www.newdomain.com/';

DECLARE @intArticleID int
DECLARE @strArticleText nvarchar(max)
DECLARE MSGCURSOR CURSOR FOR 
SELECT ArticleID, ArticleText FROM InstantKB_Articles
WHERE ArticleText LIKE '%' + @searchFor + '%';

OPEN MSGCURSOR

FETCH NEXT FROM MSGCURSOR
INTO @intArticleID, @strArticleText

WHILE @@FETCH_STATUS = 0
BEGIN

SET @strArticleText = REPLACE(@strArticleText, @searchFor, @replaceWith)

UPDATE InstantKB_Articles SET
InstantKB_Articles.ArticleText = @strArticleText
WHERE ArticleID = @intArticleID

FETCH NEXT FROM MSGCURSOR
INTO @intArticleID, @strArticleText

END
-- tidy cursor
CLOSE MSGCURSOR
DEALLOCATE MSGCURSOR

GO

That's It!

We hope this script example is helpful. Of course if we can assist with any questions please don't hesitate to contact us or open a support ticket


Optionally provide private feedback to help us improve this article...

Thank you for your feedback!


Comments require login or registration.

Details

Product: InstantKB
Version: All Versions
Type: HOWTO
Article not rated yet.
Article has been viewed 5.1K times.
Last Modified: 4 Years Ago
Last Modified By: Ryan Healey

Options

Similar Articles


Tags