CONTAINS(T-SQL) with many variable

  • I created full text catalog & full text index in column Name,Description of table Product

    when I write

    1:

    SELECT Name,Description

    FROM dbo.Product

    WHERE CONTAINS((Name,Description),'Funny OR romance')

    --return 2 rows

    but when using CONTAINS with variables

    2:

    DECLARE @Word1 varchar(15)

    SET @Word1 = 'Funny'

    DECLARE @Word2 varchar(15)

    SET @Word2 = 'romance'

    SELECT Name,Description

    FROM dbo.Product

    WHERE CONTAINS(*,'@Word1 OR @Word2')

    --rerturn 0 row

    -- I wonder false in snippet (*,'@Word1 Or @Word2')

    if i write

    3:

    DECLARE @Word1 varchar(15)

    SET @Word1 = 'Funny'

    DECLARE @Word2 varchar(15)

    SET @Word2 = 'romance'

    SELECT Name,Description

    FROM dbo.Product

    WHERE CONTAINS(*,@Word1 OR @Word2)

    -- no comply

    help me correct the problem for program work same as 1(use variables)

    thanks

  • Read the syntax of the CONTAINS clause in the Books Online (BOL): http://technet.microsoft.com/en-us/library/ms187787(SQL.90).aspx

    If you use a variable all terms, including the "OR", in the query specification must be placed in the variable.


    [font="Arial Narrow"](PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.[/font]

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply