How to find and replace a string in a table?

  • Hi experts,

       In SS2000, I have a table which stores all the file path data.  Now the server will be swapped out and the server name will be changed as well, so that the server will point to the right path to retrieve files. The old server name is MKPDC, the new one is SVR01. 

    How to search and replace MKPDB by SRV01 in all column’s data in the particular table, say table name = INETObjectProperties.  Does anyone have a sample store procedure or a script? 

    The sample of data : N="CRAWLDESC">This crawler will retrieve documents from the '\\Mkpdc\intranet\Marketing\Best Practices\Marketing and Sales Initiatives\Increase Party Size' folder, and its child folders.

    Thank you very much.

  • UPDATE YourTable

    SET YourColumn = STUFF(YourColumn, 3, 5, 'SRV01')

    WHERE YourColumn LIKE '\\mkpdc%'

    --
    Adam Machanic
    whoisactive

  • Or...

    UPDATE YourTable

    SET YourColumn = STUFF(YourColumn, CHARINDEX(YourColumn, 'mkpdc'), 5, 'SRV01')

    --
    Adam Machanic
    whoisactive

  • Why not simply

    UPDATE table SET Column  = REPLACE(Column, 'mkpdc', 'SRV01')



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Is it just one table?

    If not check this thread:-

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=145126

    Have fun

    Steve

    We need men who can dream of things that never were.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply