How do you escape double quotes inside a SQL fulltext 'contains' function?

后端 未结 2 444
生来不讨喜
生来不讨喜 2020-12-20 16:21

How do you escape a double quote character inside a MS SQL \'contains\' function?

SELECT decision
FROM table 
WHERE CONTAINS(decision, \'34\" AND wide\')
         


        
2条回答
  •  北荒
    北荒 (楼主)
    2020-12-20 17:00

    The above answer does not work in SQL Server 2008 if your string is for a single-digit number.

    This works:

    SELECT  partdescription
    FROM    table  
    WHERE   CONTAINS(partdescription, '10') 
            AND decision LIKE '%10"%'
    

    This doesn't work:

    SELECT  partdescription
    FROM    table  
    WHERE   CONTAINS(partdescription, '6') 
            AND decision LIKE '%6"%'' 
    

    EDIT: Explanation of why a single digit may not be indexed.

    If the SYSTEM stop word (or noise word) list is being used it contains each of the numeric digits as words to be ignored. You can change the contents of the Stop Word list or you can turn off the Stop Words altogether.

     ALTER FULLTEXT INDEX ON dbo.my_ft_table SET STOPLIST = OFF;
    

    Once one of these changes is made, the text affected must be reindexed before the single digits become searchable. After the reindexing it will indeed be possible to search for '6'.

提交回复
热议问题