Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006
    Location
    Leeds, UK
    Posts
    104

    Unanswered: regular expression?

    Hi

    I'm looking to return rows from a table where a column is LIKE a keyword. This is my current code:

    Code:
    SELECT DISTINCT business_name FROM Table WHERE business_name LIKE @keyword + '%' ORDER BY business_name ASC
    The problem with this is that if a business is called "The White Ship Inn", and the keyword to match is "White Ship" it will not match. If i put another wild card in front of @keyword then this finds too many matches - i need it to match against columns which either start with the keyword, or have a whitespace in front of them. Is there some kind of T-Sql i can use or will i have to go down the regex route (using this) ?

    cheers
    Last edited by mattock; 03-25-08 at 07:46.

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Code:
    SELECT DISTINCT business_name 
    FROM Table 
    WHERE business_name LIKE @keyword + '%' 
    OR 
    business_name LIKE '% ' + @keyword + '%' 
    ORDER BY business_name ASC
    ???
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Aug 2006
    Location
    Leeds, UK
    Posts
    104
    oh come on pootle, you should know by now i like to make things harder for myself! lol

    cheers (again)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •