我正在 ASP.NET 应用程序中执行 SQL 前缀搜索。为此,我编写了一个存储过程,在其中编写以下查询:
SELECT Description, ProductDescriptionID
FROM Production.ProductDescription
WHERE CONTAINS (Description, ' "top*" ' );
我的程序中的参数为 @pvchProductName
。如何用上述查询中的参数值替换 top 单词?我面临单引号和双引号的语法问题.
最佳答案
DECLARE @searchTerm nvarchar(60) = N' "' + @pvchProductName + N'*" ';
// where the "60" above should be adjusted to account for the length
// of pvchProductName, plus 5. So if pvchProductName is [n]varchar(30),
// then nvarchar(35) would be fine.
SELECT Description, ProductDescriptionID
FROM Production.ProductDescription
WHERE CONTAINS (Description, @searchTerm);
?
但是,尚不清楚您要在过滤条件中包含多少引号/星号/空格 - 您可能需要稍微检查一下。
关于c# - 如何将参数值放入SQL的前缀搜索中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13006735/