SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Finding and replacig commas in mysql

    I tried this but it doesn't seem to work.

    UPDATE `livesite` SET `guid` = REPLACE(`guid`,',','-');

    I then thought it was a simple case of exscaping the comma and tried this, which didnt' work either.

    UPDATE `livesite` SET `guid` = REPLACE(`guid`,'\,','-');

    How can I replace commas with hyphens or dashmarks in my column?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    define "doesn't seem to work"

    watch, i can make it work just fine --
    Code:
    CREATE TABLE livesite
    ( id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT
    , guid VARCHAR(99)
    );
    INSERT INTO livesite (guid) VALUES
     ( 'value.with.no.commas' )
    ,( 'value,with,commas' )
    ;
    SELECT * FROM livesite
    ;
    UPDATE livesite SET guid = REPLACE(guid,',','-')
    ;
    SELECT * FROM livesite
    ;
    if you run that code, you'll see that it actually ~does~ work

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

  3. #3
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's odd. I don't know why, but I couldn't get it to work earlier.
    (I'll admit I was using it in a trigger and it said the error occured right before the above t so I thought that was the problem). *shrugs*


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
  •