Replace -- fails to "WRITE" changes to DB

  • How can I change the following so

    REPLACE "writes" changes to the database

    instead of the current "display new results,

    don't write changes" like it currently does ?

    SELECT REPLACE(NAME,

    SUBSTRING(NAME, CHARINDEX('2004',

    NAME), 4), '2005')

    FROM         dbo.[PRODUCT]

    WHERE     (NAME LIKE '%2004%')

  • Use an update statement.

    update product

    set name = REPLACE(NAME, '2004', '2005')

    where  (NAME LIKE '%2004%')

    In your query,

    SUBSTRING(NAME, CHARINDEX('2004',

    NAME), 4)

    would ultimately return you '2004' itself. So I have directly used '2004' in the update statement.

Viewing 2 posts - 1 through 1 (of 1 total)

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