• jhutchings (10/7/2015)


    Hi Folks,

    I'm trying to replace a particular part of a row in a table with a new value.

    The row is called "DataPath" and it has a lot of values like so:

    \\mash\Operations\Component Data Files\Santec

    I want to run a query to replace the \\mash\ with our DFS namespace share name \\company\shares\Departments\ but keep everything else past the \\mash part of the original row.

    I'm currently running this query, it says it is altering 30,000 rows, but it doesn't look like it's doing anything at all..

    UPDATE dbo.Part

    SET DataPath = REPLACE(DataPath,'\\company.local\shares\Departments\','\\mash\')

    WHERE DataPath like '\\mash\%'

    So for example, it would change the \\mash above to

    \\company.local\shares\Departments\Operations\Component Data Files\Santec

    I think you have your arguments 2 and 3 the wrong way around: from BOL,

    "REPLACE ( string_expression , string_pattern , string_replacement )"

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden