2013-02-20 66 views
1

我正在嘗試使用全文搜索執行sp_executesql。sp_executesql以及全文搜索和formsof inflectional

此查詢工作正常。

exec sp_executesql 
    N'SELECT TOP (@p0) this_.org_id as y0_, this_.u_Name as y1_, this_.Category as y2_ FROM Organization this_ 
    WHERE contains (this_.u_Name,@p1)' 
    ,N'@p0 int,@p1 nvarchar(4000)', 
    @p0=1000,@p1=N'service' 

但我不得不添加一個字變化的FORMSOF屈折,然後它看起來像參數@ P1是現在的空白,並且查詢返回任何結果。任何原因 ?如果我用實際的單詞「service」替換@ p1,一切正常。

exec sp_executesql 
N'SELECT TOP (@p0) this_.org_id as y0_, this_.u_Name as y1_, this_.Category as y2_ FROM Organization this_ 
WHERE contains (this_.u_Name,''formsOf(inflectional, @p1)'')' 
,N'@p0 int,@p1 nvarchar(4000)', 
@p0=1000,@p1=N'service' 

回答

0

在formsOf()中你的變量@ p1變成了一個字符串。試試這個:

exec sp_executesql 
N'declare @ft nvarchar(4000) 
set @ft = ''formsof(inflectional, '' + quotename(@p1, ''"'') + '')'' 
SELECT TOP (@p0) this_.org_id as y0_, this_.u_Name as y1_, this_.Category as y2_ FROM Organization this_ 
WHERE contains (this_.u_Name,@ft)' 
,N'@p0 int,@p1 nvarchar(4000)', 
@p0=1000,@p1=N'service'