Share via


Integrieren von Volltextsuche und Transact-SQL-Prädikaten

Die Prädikate CONTAINS und FREETEXT können mit jedem anderen Transact-SQL-Prädikat, z. B. LIKE und BETWEEN, kombiniert und in einer Unterabfrage verwendet werden. Im folgenden Beispiel wird nach Beschreibungen gesucht, deren ID ungleich 5 ist und die das Wort "Aluminum" und das Wort "spindle" enthalten.

USE AdventureWorks;
GO
SELECT Description
FROM Production.ProductDescription
WHERE ProductDescriptionID <> 5 AND
   CONTAINS(Description, ' Aluminum AND spindle');
GO

Die folgende Abfrage verwendet CONTAINS in einer Unterabfrage. Mithilfe der AdventureWorks-Datenbank ruft die Abfrage den Kommentarwert aller Kommentare in der ProductReview-Tabelle für einen bestimmten Zyklus ab.

USE AdventureWorks;
GO
INSERT INTO Production.ProductReview 
(ProductID, ReviewerName, EmailAddress, Rating, Comments) 
VALUES
(780, 'John Smith', 'john@fourthcoffee.com', 5, 
'The Mountain-200 Silver from AdventureWorks Cycles meets and exceeds expectations. I enjoyed the smooth ride down the roads of Redmond')
 -- Given the full-text catalog for these tables is Adv_ft_ctlg, 
-- with change_tracking on so that the full-text indexes are updated automatically.
WAITFOR DELAY '00:00:30'   
-- Wait 30 seconds to make sure that the full-text index gets updated.
  SELECT r.Comments, p.Name
FROM Production.ProductReview r
JOIN Production.Product p 
ON
 r.ProductID = p.ProductID
 AND r.ProductID = (SELECT ProductID
                  FROM Production.ProductReview
                  WHERE CONTAINS (Comments, 
                                 ' AdventureWorks AND 
                                   Redmond AND 
                                   "Mountain-200 Silver" '))

GO

Siehe auch

Andere Ressourcen

CONTAINS (Transact-SQL)
FREETEXT (Transact-SQL)
WHERE (Transact-SQL)

Hilfe und Informationen

Informationsquellen für SQL Server 2005