将多个单词组合成单个字符串值 [英] combine multiple word into single string value

查看:80
本文介绍了将多个单词组合成单个字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sql server中使用自由文本搜索

我的sp就像

I am Using free text search in sql server
my sp is like

Create procedure [dbo].[spExactSearch]
(
  @Keyword nvarchar(255)
)
AS
 BEGIN
 SELECT
       TenderID
      ,TenderTitle
      ,ProductCatID
      ,P.ValueTypeName as ProductCatName
      ,TenderValue
      ,Location
      ,LastDateForSubmission
FROM TenderDetail TD(NOLOCK)
INNER JOIN
   ValueType P(NOLOCK)
   ON
   TD.ProductCatID=P.ValueTypeID
WHERE CONTAINS((ProductSubCatName), @Keyword)
Order By TD.CreatedDate desc
END



问题是这个单词工作正常但是当我使用超过1个单词

然后它会抛出错误而我不想使用自由文本

可以有人建议像@keyword中的值一样自由文本将它计为单个单词,如果我使用存储过程代替@keyword那么它的工作正常
感谢您的帮助.....


the problem is this is working fine for 1 word but when i am using more than 1 word
then it throws an error and i don't want to use Free Text
can someone suggest something like whatever be the value comes in @keyword free text count it as a single word like if i am Using "Stored Procedure" in place of @keyword then its working fine
thanks for help.....

推荐答案

希望有用,

Hope helpful,
--You can store each word with single quote separated by commas into @Keyword variable
--Pass string with single quote ' seperated by , comm

Declare @Keyword varchar(200) = '''First'',''third'',''fifth'''
Declare @Query varchar(500)

set @Query = 'select * from TenderDetail where ProductSubCatName in (' + @Keyword + ')'

exec (@Query)


这篇关于将多个单词组合成单个字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆