Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Posts
    2

    Unanswered: update a number -- can't figure it

    This is probably the simplest question, but Im a newbie at this. I have searched and searched this forum with no luck maybe Im just not using the right search words so here is my issue

    In MySQL database I Need to replace certain numbers with another number.
    Here is my query that for the most part it works

    update users set credits = replace(credits, '9', '20')

    This works fine, except that it also turns the 19 into 120

    What can I do to replace ONLY the 9 and NOT the 19

    Here is another example

    update users set credits = replace(credits, '2', '20')

    in this case if there are any 20 it will replace them with 200
    of if there are any 22 it will replace them with 2020

    The field is INT

    Thank for any help anyone can provide

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Quote Originally Posted by mariodac
    This is probably the simplest question, but Im a newbie at this. I have searched and searched this forum with no luck maybe Im just not using the right search words so here is my issue

    In MySQL database I Need to replace certain numbers with another number.
    Here is my query that for the most part it works
    [...]
    The field is INT

    Thank for any help anyone can provide
    REPLACE is for character columns, you want a simple update with a WHERE clause:
    Code:
    UPDATE users 
       SET credits = 20 
      WHERE credits = 9;
    Will change the credits for any row where the value is 9 to 20

  3. #3
    Join Date
    Jun 2009
    Posts
    2
    shammat

    Thank you very much
    worked great

Posting Permissions

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