Perform a full text query using the CONTAINS clause in the FROM clause of a SELECT statement, or by using the CONTAINS search condition (predicate) in a WHERE clause.
Both methods return the same rows; however, the CONTAINS clause also returns scores for the matching rows.
CONTAINS ( column-name [,...], contains-query-string ) contains-query-string: simple-expression | or-expression simple-expression: primary-expression | and-expression or-expression: simple-expression { OR | | } contains-query-string primary-expression: basic-expression | FUZZY " fuzzy-expression " | and-not-expression and-expression: primary-expression [ AND | & ] simple-expression and-not-expression: primary-expression [ AND | & ] { NOT | - } basic-expression basic-expression: term | phrase | ( contains-query-string ) | proximity-expression fuzzy-expression: term | fuzzy-expression term term: simple-term | prefix-term prefix-term: simple-term* phrase: " phrase-string " proximity-expression: term ( BEFORE | NEAR ) [ minimum distance, | maximum distance ] term | term {BEFORE | NEAR | ~ } term phrase-string: term | phrase-string term
BEFORE is like NEAR, except that the order of terms is significant. 'b BEFORE c' is not equivalent to 'c BEFORE b'; in the former, the term 'b' must precede 'c' while in the latter the term 'b' must follow 'c'. BEFORE accepts both minimum and maximum distances like NEAR. The default minimum distance is 1. The minimum distance, if given, must be less than or equal to the maximum distance; otherwise, an error is returned.
The CONTAINS search condition takes a column list and contains-query-string as arguments.
The CONTAINS search condition can be used anywhere a search condition (also referred to as predicate) can be specified, and returns TRUE or FALSE. contains-query-string must be a constant string, or a variable, with a value that is known at query time.
If multiple columns are specified, then they must all refer to a single base table; a TEXT index cannot span multiple base tables. You can reference the base directly in the FROM clause, or use it in a view or derived table, provided that the view or derived table does not use DISTINCT, GROUP BY, ORDER BY, UNION, INTERSECT, EXCEPT, or a row limitation.
Queries using ANSI join syntax are supported (FULL OUTER JOIN, RIGHT OUTER JOIN, LEFT OUTER JOIN), but may have suboptimal performance. Use outer joins for CONTAINS in the FROM clause only if the score column from each of the CONTAINS clauses is required. Otherwise, move CONTAINS to an ON condition or WHERE clause.
If you use a SQL variable less than 32KB in length as a search term and the type of variable is LONG VARCHAR, use CAST to convert the variable to VARCHAR data type. For example:
SELECT * FROM tab1 WHERE CONTAINS(c1, cast(v1 AS VARCHAR(64))
Within phrases, the asterisk is the only special character that continues to be interpreted as a special character. All other special characters within phrases are treated as white space and serve as term breakers.