Tips for Searching using SQL
Use the SELECT statement to retrieve rows. The SELECT statement consists of:
Example
SELECT DocAuthor, size, DocTitle
FROM SCOPE(' "/IISSamples/ISSamples" ') WHERE CONTAINS(' "index server" ') > 0 ORDER BY size
The FROM clause of the SELECT statement is used to specify the files on which to perform the search; that is, use the FROM clause to define the query scope. You can use the SCOPE() function, which is the main component of the FROM clause. The SCOPE function can take zero or more comma-separated Scope_Arguments (that is, Traversal_Type and Path combinations). You can specify SCOPE with an empty argument list, or (). This is the default scope that uses the virtual root ( / ) as its path. Each Scope_Argument must be surrounded by single quotes (see Examples below).
In addition to using Scope(), you can also refer to any one of a set of predefined views of Indexing Service properties that are often queried against. You can reference one of these pre-defined views in the FROM clause by specifying the pre-defined View_Name.
Examples
SELECT DocAuthor, size
SELECT * FROM EXTENDED_WEBINFO
SELECT DocAuthor, size FROM SCOPE() WHERE size > 500000
FROM SCOPE(' SHALLOW TRAVERSAL OF "D:\Contracts\open" ',' DEEP TRAVERSAL OF "/Reports/Year 97" ')
WHERE CONTAINS(DocAuthor, ' "John" ') > 0
WHERE CONTAINS(DocSubject, ' "index server" NEAR() "internet information server" ') > 0
The WHERE clause of the SELECT statement specifies which rows in the virtual table defined by the FROM clause make up the resulting rowset. The WHERE clause consists of one or more search conditions (that is, one or more predicates combined with AND, OR and NOT) that filter out rows for which the search condition is false.
Examples
SELECT FileName, DocAuthor FROM FILEINFO WHERE size < 10000 OR DocWordCount <= 800
SELECT DocTitle, FileName, write FROM SCOPE()
SELECT FileName, size FROM SCOPE() WHERE DocTitle = 'Financial Data' OR DocAuthor = 'John Smith'
WHERE CONTAINS (' "Index" NEAR() "Server" NEAR() "Microsoft"') > 0 AND size < 5000
The optional ORDER BY clause can be appended to the SELECT statement to sort the rows returned in the rowset according to a specified set of criteria. Results are sorted by default in ascending order. To sort in descending order, specify DESC after the column name.
Example
SELECT FileName, DocTitle, size, rank FROM SCOPE(' "/MyDocs/Specs97", "/YourDocs/Specs97" ')
WHERE FREETEXT (' "How do I index my HTML pages" ') > 0 ORDER BY rank, size DESC
For a more detailed description of the SQL syntax supported in Indexing Service, including use of the CONTAINS and FREETEXT predicates as illustrated in the examples on this page, please refer to the SQL Access To Indexing Service Data page in the product documentation.