none
search and replace RRS feed

  • Question

  •  

    I'm having a problem doing a search and replace with SQL 2005 Mangement Studio. I need to go into a table column and do a search and replace. Edit > Find & Replace doesn't seem to do what I want to do.

     

    A "NEW QUERY" makes the changes, but not in the actual table. My problem is not in what to do, but in how to do it in SQL 2005 Management Studio.

     

    Thx

     

     

    Saturday, October 4, 2008 7:20 PM

Answers

  • There is no "Search and Replace" for data.  You need to write a TSQL update statement to do that.

    It would normally look something like this

    UPDATE MyTable
    SET MyColumn = 'Something else'
    WHERE
    <criteria>

    in your case, the SET MyColumn = 'SomethingElse' could be replaced by

    SET MyColumn = REPLACE(MyColumn, 'Something To Find', 'Something to Replace it with')
    Sunday, October 5, 2008 3:07 PM
    Moderator

All replies

  • Do you want to update a table, update a column, update a record, update a field?

     

    A.D.T.

     

    Saturday, October 4, 2008 7:23 PM
  •  I don't need to update.  All the records (over 1000) in a column has a phrase: "Updated by xxx"

     

    I want to do a simple search and replace such as open database; open table; select column and do a search and replace.

     

    or use the REPLACE function.

     

    The REPLACE function works but the Management Studio creates a copy, it doesn't apply it the working table.

     

     

     

     

    Saturday, October 4, 2008 7:30 PM
  • Ok good luck

     

    A.D.T.

     

    Saturday, October 4, 2008 8:03 PM
  • There is no "Search and Replace" for data.  You need to write a TSQL update statement to do that.

    It would normally look something like this

    UPDATE MyTable
    SET MyColumn = 'Something else'
    WHERE
    <criteria>

    in your case, the SET MyColumn = 'SomethingElse' could be replaced by

    SET MyColumn = REPLACE(MyColumn, 'Something To Find', 'Something to Replace it with')
    Sunday, October 5, 2008 3:07 PM
    Moderator
  •  

    I think You are looking for the search and replace the data that is stored in the tables.

    This article might help you http://vyaskn.tripod.com/sql_server_search_and_replace.htm

     

    Thanks

    -Paramjit

    Sunday, October 5, 2008 7:26 PM
  •  

    FOUND the SEARCH and REPLACE!

     

     

    1)

    UPDATE MyTable
    SET MyColumn = REPLACE(MyColumn, 'Something To Find', 'Something to Replace it with')
     
     
    2) Go to "New Query" and run the query.
    3) Go to the table you want the query to execute and select Execute.
     
    thanks all for your help
     
    GLM
     
    Monday, October 6, 2008 9:04 PM