SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Replace help?

  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replace help?

    Hi Guys,

    I've googled this but can't find the right answer. Say I want to replace all instances of the character & in my database for 1,000's of records.

    I thought it would be something like so:

    Code:
    update table set headline = replace('&','&');
    Can anyone help?

  2. #2
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Beware

    Haven't actually tried this - but be careful: what about if you already have some cases of '&amp' in your database and you replace the '&' then they will end up as '&&amp'.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,015
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by chris_stfc View Post
    I thought it would be something like so:

    Code:
    update table set headline = replace('&','&');
    pretty close, but your REPLACE function was missing a parameter

    UPDATE table SET headline = REPLACE(headline,'&','&');

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Evangelist
    Join Date
    Apr 2007
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Say I wanted to replace the ' character with Thanks. Say I wanted to replace the ' character:
    with & # 39;

    Does not seem to like it?:

    Code:
    UPDATE table SET headline = REPLACE(headline,''',''');
    Does not seem to like it?

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,015
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Code:
    UPDATE table SET headline = REPLACE(headline,'''',''')
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •