1

我正在尝试在其中执行带有全文搜索的 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 现在是空白的,并且查询没有返回任何结果。任何原因 ?如果我将@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'
4

1 回答 1

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'
于 2013-06-20T05:58:28.453 回答