sp_executesql以及全文搜索和形式的屈折

时间:2013-02-20 02:05:14

标签: sql sql-server full-text-search sp-executesql

我正在尝试使用全文搜索来执行sp_executesql。

此查询工作正常。

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'

但是我必须为单词变体添加一个变形形式,然后它看起来像参数@ 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'

1 个答案:

答案 0 :(得分:0)

在形式的()中你的变量@ 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'