Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error near 'of' in the full-text search condition 'control of'

I have the following WHERE clause:

WHERE (@Keywords IS NULL             OR (CONTAINS((p.Title, p.Area, p.[Message]), @Keywords))         ) 

If @Keywords = 'control', then the query executes successfully and filters my records

If @Keywords = 'control of', then I get the following error:

Syntax error near 'of' in the full-text search condition 'control of'.

Why is this and what can I do to resolve the issue?

The main reason I'm using this method over using LIKE condition is so that I can search multiple words.

like image 532
Curtis Avatar asked Feb 24 '12 17:02

Curtis


People also ask

What is syntax error at or NEAR?

This SQL error generally means that somewhere in the query, there is invalid syntax. Some common examples: Using a database-specific SQL for the wrong database (eg BigQuery supports DATE_ADD, but Redshift supports DATEADD) Typo in the SQL (missing comma, misspelled word, etc)

Why am I getting a syntax error in SQL?

Misspellings are the most common cause for error in SQL. Unfortunately, SQL will not autocorrect mistyped keywords, tables, columns, or values. Check keyword spelling by referring to the documentation for the type of SQL you are using.

What is the SQL error?

SQLError() returns the diagnostic information associated with the most recently called DB2® for i CLI function for a particular statement, connection, or environment handle. The information consists of a standardized SQLSTATE, an error code, and a text message.


1 Answers

Enclose the keywords in double quotes if you want to search exactly for control of

SET @Keywords = '"control of"' 

If you want to search for control and of, use the following:

SET @Keywords = 'control AND of' 

But server may consider of as a garbage or stop word, so in this case use the following:

SET @Keywords = 'control AND "of"' 
like image 157
Oleg Dok Avatar answered Sep 19 '22 07:09

Oleg Dok