将数据库列作为参数传递给Contains或Freetext

时间:2013-02-02 15:37:38

标签: sql sql-server-2008 contains freetext

我试图将可搜索的列作为参数传递给存储过程,但它永远不会工作

contains(@RTitleColumn, @searchTerm) 

我将@RtitleColumn作为第一个CONTAINS参数传递

这是完整的查询

SELECT  Lid As ItemID, Lhits As Hits, LImageID As ImageID, LNAME As Title
            , LCategory AS CategoryID, Lactive AS isActive,LRate AS SumRate,LRAteNo AS CommentCount,
            ROW_NUMBER() OVER (ORDER BY LID desc) AS RowRank
            FROM    dbo.tblRecipes
            where
            contains(@RTitleColumn, @searchTerm) and (@Activeflag is null or LActive=@Activeflag)

1 个答案:

答案 0 :(得分:0)

(假设参数@ searchTerm被声明为nvarchar(50)

Declare @MainSQL nvarchar(200)



set @MainSQL =  


    N'SELECT Lid As ItemID, Lhits As Hits,LImageID As ImageID, 
       LNAME As Title, LCategory AS CategoryID, Lactive AS isActive, 
       LRate AS SumRate,LRAteNo AS CommentCount, 
       ROW_NUMBER() OVER (ORDER BY LID desc) AS RowRank 
       FROM    dbo.tblRecipes 
       where                                  
       contains(' + @RTitleColumn + ', @searchTerm)'

Execute sp_executesql, @MainSQL, N'@searchTerm nvarchar(50)',@searchTerm = @searchTerm