Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Full-Text Search Equivalent of LIKE '%'?

I am using the FTS option of sql server 2008. In my queries, I would like to pass in a wildcard search.

In std sql, I have this:

SELECT * 
  FROM Person 
WHERE Lastname like '%';  -- this returns all persons

Using FTS, I would like to do something like this:

SELECT * 
  FROM Person 
 WHERE contains(*, '"*"')  -- this return no rows.

The reason I have contains is because i am passing a parameter to an sp.

For example:

exec spMySearch('formsof (inflectional, stuff)')

In spMySearch(), I have this:

select * from Person where contains(*, @SearchBy)  -- this is the param of spMySearch

Is there an approach you can recommend to getting wildcard searches? I know there is a performance hit, but it is something I would like to try and get working.

like image 933
Steve Avatar asked Dec 31 '25 20:12

Steve


1 Answers

contains('"*"') will return zero records by design.

Is there some reason you need to do that though? Why not just do the query without the parameter if it's empty?

IF @SearchBy = '' BEGIN
    SELECT  *
        FROM    Person
END
ELSE BEGIN
    SELECT  *
        FROM    Person
        WHERE   CONTAINS(*, @SearchBy)
END
like image 119
Tory Netherton Avatar answered Jan 02 '26 11:01

Tory Netherton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!