"Find and Replace" Values in a Database

Last post 03-05-2009 7:45 PM by adamargyle. 4 replies.

Sort Posts:

  • "Find and Replace" Values in a Database

    03-03-2009, 6:01 PM
    • Member
      9 point Member
    • adamargyle
    • Member since 12-13-2007, 6:45 AM
    • Posts 126

    Is there a way to go through a database and just delete/update to null the records of a particular value

    So for example if you had the values

    director            producer            writer              leadrole
    bob holness     bob holness        bob holness
    wayne smith    wayne smith                            bob holness

    And you want to delete any entry of bob holness from the database, but without deleting the whole record, so for example wayne smith would remain.
    Is this possible?

  • Re: "Find and Replace" Values in a Database

    03-03-2009, 9:23 PM
    • Participant
      1,084 point Participant
    • amitchandnz
    • Member since 01-19-2009, 10:41 PM
    • Auckland, New Zealand
    • Posts 231

    You could carry out a search and replace routine as I have created on my blog:

    This link is for a routine to search for a particular text in all database columns that hold text:
    http://amitchandnz.wordpress.com/2009/02/26/search-text-in-all-tables/

    This link is for a routine to search and replace text in all database columns that hold text:
    http://amitchandnz.wordpress.com/2009/02/10/search-replace-database-column-text/

  • Re: "Find and Replace" Values in a Database

    03-04-2009, 6:07 AM
    • Member
      9 point Member
    • adamargyle
    • Member since 12-13-2007, 6:45 AM
    • Posts 126

    Thanks for the link

    but when I try creating the procedure http://amitchandnz.wordpress.com/2009/02/10/search-replace-database-column-text/

    I get the message #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@iSearchString VARCHAR(100)
                    ,@iReplaceString VARCHAR(100)

    I am using MySQL client version: 4.1.22

  • Re: "Find and Replace" Values in a Database

    03-04-2009, 3:14 PM
    • Participant
      1,084 point Participant
    • amitchandnz
    • Member since 01-19-2009, 10:41 PM
    • Auckland, New Zealand
    • Posts 231

     Ah sorry about that, I wrote those scripts for SQL Server 2005 as that is what I work on.

  • Re: "Find and Replace" Values in a Database

    03-05-2009, 7:45 PM
    • Member
      9 point Member
    • adamargyle
    • Member since 12-13-2007, 6:45 AM
    • Posts 126

    I am using the syntax: REPLACE(str,from_str,to_str)

    to replace data in my table. However I have a slight issue I would like to address, when I have the following records

    jon  | jonathon | jonas | jonny

    and I do the replace with

    REPLACE(names, jon, '')

    I am left with 

         | athon | as | ny

    Is there a way that it can only replaces 'whole words' and not replace the string where it is part of a larger string?


     

     

     


Page 1 of 1 (5 items)