全文搜索多列获取哪些列匹配

时间:2017-08-03 13:50:20

标签: sql-server full-text-search

我在SQL Server中使用全文搜索,我有一个类似的查询:

SELECT  [Column 12] AS Column_12 ,
        [Column 0] AS Column_0 ,
        [Column 13] AS Column_13 ,
        [Column 3] AS Column_3 ,
        [Column 4] AS Column_4 ,
        [Column 14] AS Column_14 ,
        [Column 5] AS Column_5 ,
        [Column 2] AS Column_2
FROM    dbo.allCountries
WHERE   CONTAINS (( [Column 12], [Column 0], [Column 13], [Column 3],
        [Column 4], [Column 14], [Column 5], [Column 2]), @Location )

我需要的是获得与搜索值匹配的列。如果搜索在多个列中匹配,我需要获取他们的名字或索引。

1 个答案:

答案 0 :(得分:0)

根据您的要求:

private dynamic

返回select id, [column], value from ( SELECT [id] ,[column 0],[column 1] ,[column 2],[column 3] ,[column 4],[column 5] FROM [dbo].[allcountries] where contains (*, @location) ) tmp UNPIVOT ( value for [column] in ([column 0],[column 1],[column 2],[column 3],[column 4],[column 5]) ) up where value like '%' + @location + '%' (标识,PK)字段,id名称([列#])和搜索值(@location)

相关问题