如何从表中找到具有单引号字符串的字符串?

时间:2021-12-11 10:50:55

Here is my input @Name as "Rupesh's"

这是我的输入@Name为"Rupesh "

I want to find 'Rupesh's' like name from the table 'AppliedPolicies' table

我想从“应用策略”表中找到“Rupesh”的名字。

Select PolicyID, CustomerName, PolicyDesc 
From AppliedPolicies 
Where PolicyDesc = @Name

Plz. suggest me how could i get the required result.

请。建议我怎样才能得到要求的结果。

5 个解决方案

#1


3  

Try this

试试这个

Select PolicyID, CustomerName, PolicyDesc 
From AppliedPolicies 
Where PolicyDesc like '%' + @Name + '%'

#2


1  

Select PolicyID, CustomerName, PolicyDesc From AppliedPolicies
Where PolicyDesc like'%Rupesh'

for more http://www.w3schools.com/sql/sql_like.asp

更多的http://www.w3schools.com/sql/sql_like.asp

#3


1  

You need to add another single quote to escape the single quote in the name, i.e. 'Rupesh''s'

您需要添加另一个单引号以避免名称中的单引号,即。“Rupesh“s”

Example:

例子:

declare @name varchar(20) = 'Rupesh''s'

SELECT * FROM
AppliedPolicies
WHERE PolicyDesc = @Name

#4


0  

According to your title, maybe try this:

根据你的头衔,试试这个:

  Select  
      PolicyID,  
      CustomerName,  
      PolicyDesc  
  From 
      AppliedPolicies  
  Where 
      PolicyDesc like '%''%'

#5


0  

Try this SQL

试试这个SQL

    Select PolicyID, CustomerName, PolicyDesc 
    From AppliedPolicies 
    Where Replace(PolicyDesc,'''','_') = Replace(**@Name**,'''','_')

#1


3  

Try this

试试这个

Select PolicyID, CustomerName, PolicyDesc 
From AppliedPolicies 
Where PolicyDesc like '%' + @Name + '%'

#2


1  

Select PolicyID, CustomerName, PolicyDesc From AppliedPolicies
Where PolicyDesc like'%Rupesh'

for more http://www.w3schools.com/sql/sql_like.asp

更多的http://www.w3schools.com/sql/sql_like.asp

#3


1  

You need to add another single quote to escape the single quote in the name, i.e. 'Rupesh''s'

您需要添加另一个单引号以避免名称中的单引号,即。“Rupesh“s”

Example:

例子:

declare @name varchar(20) = 'Rupesh''s'

SELECT * FROM
AppliedPolicies
WHERE PolicyDesc = @Name

#4


0  

According to your title, maybe try this:

根据你的头衔,试试这个:

  Select  
      PolicyID,  
      CustomerName,  
      PolicyDesc  
  From 
      AppliedPolicies  
  Where 
      PolicyDesc like '%''%'

#5


0  

Try this SQL

试试这个SQL

    Select PolicyID, CustomerName, PolicyDesc 
    From AppliedPolicies 
    Where Replace(PolicyDesc,'''','_') = Replace(**@Name**,'''','_')