Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Text Search - Contains

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-04-26 : 09:04:30
Eddie writes "I am using a stored procedure with ASP.NET.

SELECT ID, TITLE, DATE
FROM [DATA TABLE]

WHERE CONTAINS(title, @title)

If I use one keyword ("baseball"), it runs fine. But if I submit two keyword with blank space in between (i.e. "Baseball Bat"), error popps like this,

Syntax error occurred near 'bat'. Expected ''''' in search condition 'baseball bat'.


Any idea what I should do? Is this some kind of concatenation problem?

Thanks,"

twhelan1
Yak Posting Veteran

71 Posts

Posted - 2006-04-26 : 10:38:42
Read about CONTAINS in Books Online (BOL). Using your example, CONTAINS works like this:


SELECT ID, TITLE, DATE
FROM [DATA TABLE]
WHERE CONTAINS(title, ' "Baseball Bat" ')


If you're using a single word, what you have will work fine but for phrases, the entire phrase needs to be encapsulated in double-quotation marks (" "). This will return phrases like "I own a baseball bat" but it will not return phrases like "I hit a baseball with a bat". For that your search term would look more like ' "baseball" OR "bat" '.



~Travis
Go to Top of Page
   

- Advertisement -