Update part of a value in many rows

  • I have a table in SQLServer 2005 that has 250 rows. One of the columns contains values that are directory paths for reports. These directory paths include the name of the server. Example:

    ServerName\volume1\Folder1\subfolder1\ReportName1

    ServerName\volume1\Folder1\subfolder1\ReportName2

    Servername\volume1\Folder1\subfolder1\ReportName3

    etc.

    The server name will be the same on every row.

    How can I change just the server name on every row of the table?

    Chris from Cincinnati

  • You can use the REPLACE function


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • You can use the replace function as long as you want to replace all occurances of the server name.

    Update Table

    Set Col = Replace(Col,'ServerName','NewServerName')

    If you just want to replace the first few characters, you can build a new string using the substring function. What I am getting at here is that if for example you had...

    ServerName\data\ReportServerNameSometing

    It would now be...

    NewServerName\data\ReportNewServerNameSometing

    As long as you are ok with that, the Replace should be fine.

  • Using the REPLACE function worked perfectly! Thanks much! Especially for the detailed examples.

    Chris

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

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