Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Example
I want to search 'abc' in my table.
My table contains below words
abcde
eabcd
deabc



My query is like that but I can't get any result

create procedure searchFunction @keyword nvarchar(50)
AS
BEGIN
SET @keyword='"*'+@keyword+'*"'
SELECT * FROM table WHERE CONTAINS(words,@keyword)
END

EXEC searchFunction @keyword='abc'
Posted
Updated 26-Mar-15 3:08am
v2
Comments
Sascha Lefèvre 26-Mar-15 9:38am    
As far as I know, SQL-Server FTI doesn't allow left-side-truncation. Try removing the left asterisk and see if it finds "abcde". If you need more full-fledged FTI-functionality (including left-side-truncation), I'd recommend Lucene.Net.

1 solution

If you do not need the full text search extended features then use the Like operator:

Sql uses '%' as a full wildcard, not '*'.

More info on SQL wildcards here:

http://www.w3schools.com/sql/sql_wildcards.asp[^]


If you must use the full text search then there are some things to note about CONTAINS:

If you wish to search "starts with" then use CONTAINS('*'+term)
If you wish to search for any contains then use CONTAINS(term)

More on this here:
https://msdn.microsoft.com/en-us/library/ms187787.aspx[^]
 
Share this answer
 
v3
Comments
amagitech 26-Mar-15 9:26am    
https://msdn.microsoft.com/en-us/library/ms142583.aspx
There is some example about full text search.
But I can use @keyword='"'+@keyword+'*"' this type but this isn't meet my exceptions. This type search only 'abcd','abce'
Andy Lanng 26-Mar-15 9:36am    
oic - ur using full text search. You don't need to. A simple where 'abcde' LIKE '%abc%' would work.

If you use contains then omit the '*'s. These are not required if doing a full text search.

Punctuation is ignored. "abc def" matches "abc. def".

Unless this is highly desired, Use the Like statement. It should be more efficient
Sascha Lefèvre 26-Mar-15 9:39am    
Fulltext-Index is a different story, Andy.
Andy Lanng 26-Mar-15 9:42am    
Now I know - just trying to cover my tracks now
Solution Updated
Sascha Lefèvre 26-Mar-15 9:45am    
;-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900