LIKE usage

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gabigeo
    New Member
    • Oct 2008
    • 2

    LIKE usage

    Hi,

    I am doing this query succesfully in MySQL and I wonder why the LIKE does not work the same in MSSQL. Is there any way arround?

    MySQL: SELECT * FROM tariffs WHERE '4321' LIKE concat(prefix,' %')

    MSSQL: SELECT * FROM tariffs WHERE '4321' LIKE (prefix + '%')

    the MSSQL query returns NULL always.
    The long workarround is to make a: WHERE prefix = '4321' OR prefix = '432' OR prefix = '43' OR prefix = '4'
    but I want to avoid this.

    Anybody knows a workaround?

    Thanks
  • gabigeo
    New Member
    • Oct 2008
    • 2

    #2
    Ok, I found the solution.
    Using RTRIM like this it works:

    SELECT * FROM tariffs WHERE '4321' LIKE RTRIM(prefix) + '%'

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Originally posted by gabigeo
      Ok, I found the solution.
      Using RTRIM like this it works:

      SELECT * FROM tariffs WHERE '4321' LIKE RTRIM(prefix) + '%'

      Your where clause:

      Code:
      WHERE prefix = '4321' OR prefix = '432' OR prefix = '43' OR prefix = '4'
      is similar to

      Code:
      WHERE PREFIX like '4%'

      -- CK

      Comment

      Working...