2013-02-02 57 views
0

我試圖通過檢索列作爲參數傳遞給存儲過程,但它從來沒有工作傳遞數據庫列作爲參數包含或FREETEXT

contains(@RTitleColumn, @searchTerm) 

我傳遞的@RtitleColumn作爲第一個包含參數

這裏是完整的查詢

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 [email protected]) 
+0

您能否提供'contains' SP的詳細信息? –

+0

@GilPeretz:我很確定OP正在採取'CONTAINS' SQL Server全文搜索命令在這裏... –

+0

嗨,是的,我正在嘗試創建動態SQL並將包含搜索列字段作爲變量,它不接受具有變量,它只接受具有*或實際全文的列名稱,例如「LName」 – Moe9977

回答

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