I'm having trouble where our database has thousands of records with extra slashes in the name. However I can't seem to do any queries that will tell me which records those are, for example:

select * from MYTABLE where name like '%\%';

OR

select * from MYTABLE where name like '%\%';

OR

select * from MYTABLE where name like '%\\%';

I just get either no results or it doesn't recognize an end to my like clause.

I've googled like crazy but can't seem to find anything about this. Anyone have a suggestion?

Thanks in advance

    the slashes are there for good reason, to escape characters that would confuse the db otherwise, so they should be left alone.

      If you are running the query for MySQL on the command line or something similiar, then I would expect:

      select * from MYTABLE where name like '%\\%';

      If you are running the query in PHP, your SQL statement should be declared as:

      $sql = "select * from MYTABLE where name like '%\\\\%'";
      dagon wrote:

      the slashes are there for good reason, to escape characters that would confuse the db otherwise, so they should be left alone.

      NeoGeo is talking about the data already in the database, not data about to be sent to the database.

        woops ok, to remove them if thats what you want, you can use

        UPDATE [table] SET [field] = REPLACE([field], '\', '');

        the \ could be \\ depending how your running it as laserlight above says, the abolve does all rows in a table, so best to check it on one first by adding a where clause

          Thanks guys this worked great! I guess I just needed to try one more slash and I would have been there. The replace code made it extremely simple to repair the DB thanks!

            Write a Reply...