1

考虑这个

SELECT  * 
FROM Publication a          
INNER JOIN  CONTAINSTABLE(Publication, (Title, Keywords), 
@TitlePartial)TitleSearchPartial ON  a.Id = TitleSearchPartial.[Key]

我在表的 (TitleKeyword) 列中搜索Publication。搜索关键字可以在“标题”或“关键字”中的任何位置找到 如何找到搜索关键字在哪一列中找到?有没有开箱即用的方法来做到这一点?

有任何想法吗...

4

1 回答 1

0

你可以尝试这样的事情:

SELECT *,
    CASE
        WHEN b.[Key] IS NOT NULL THEN 'Title'
        WHEN c.[Key] IS NOT NULL THEN 'Keywords'
        END AS MatchColumn
FROM Publication a
    LEFT JOIN CONTAINSTABLE(Publication, Title, @TitlePartial) b
        ON a.Id = b.[Key]
    LEFT JOIN CONTAINSTABLE(Publication, Keywords, @TitlePartial) c
        ON a.Id = c.[Key]
WHERE (b.[Key] IS NOT NULL
        OR c.[Key] IS NOT NULL)

您可能必须添加另一个案例来匹配两列。另外,不幸的是,我现在无法对此进行测试。

于 2012-10-31T22:17:35.203 回答