SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict MarekS's Avatar
    Join Date
    Jan 2003
    Location
    Estonia / Tallinn
    Posts
    201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    LIKE search with comma (,) and period (.)

    Hi,

    In my MySQL table, I have product names. Sometimes the name contains float numbers in it. Like
    Code:
    "Abc 1.2"
    Problem is that in my country, we actually use comma as a float separator. This means that if I run SQL query
    Code:
    SELECT name FROM product WHERE name LIKE '%C 1,2%'
    - I won't receive any results.

    I'd like the items to be found with both floating separators

    Is there an easy solution for this?

    Thanks,

  2. #2
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't you replace the comma with a dot prior to generating the query?

  3. #3
    SitePoint Addict MarekS's Avatar
    Join Date
    Jan 2003
    Location
    Estonia / Tallinn
    Posts
    201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, true.

    the query will then look smth like this:

    Code:
    SELECT
      name
    FROM
      product
    WHERE
      name LIKE '%C 1,2%'
    OR
      name LIKE '%C 1.2%'
    thanks,

  4. #4
    SitePoint Evangelist
    Join Date
    May 2006
    Location
    Denmark
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm... I thought the "C 1,2" was entered by the user. If that's not the case then you may do:

    Code MySQL:
    SELECT name FROM product WHERE name REGEXP 'C 1[.,]2';


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
  •