MySQL: Replacing the first 0 with 44

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aaronwood66
    New Member
    • Oct 2008
    • 1

    MySQL: Replacing the first 0 with 44

    I have a problem I hope someone can help me with. I have about 2000 records that I need to change permentantly in a MySQL database -mobile numbers that start with 0 need to be changed so that they start with 44. I have been looking on every forum I can find but cannot find an answer. If anyone has any suggestions, I would be very very grateful. I am quite new to MySQL so go easy on me!

    Cheers,
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    MySQL has a few functions that may help with that.
    Check out the LEFT and INSERT functions.

    Be sure to back up your data before you start trying to alter it tho.

    Comment

    • tomarvijay80
      New Member
      • Nov 2006
      • 10

      #3
      Code:
      UPDATE mytable 
      SET column_name = concat('44', right(column_name,length(column_name)-1));
      this will replace first 0 from the value with 44 and concatenate the rest with 44.

      Hope this will help u.


      Thanks
      Vijay
      Last edited by Atli; Oct 6 '08, 10:17 PM. Reason: Added [code] tags.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Originally posted by tomarvijay80
        this will replace first 0 from the value with 44 and concatenate the rest with 44.
        Yes, but keep in mind that this would replace the first char of ALL records with 44, not just records starting with 0.

        Comment

        Working...