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

时间:2014-03-25 07:14:41

标签: sql sql-server sql-like

这是我输入的@Name为“Rupesh's”

我想在“AppliedPolicies”表格中找到“Rupesh's”之类的名称

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

PLZ。建议我怎样才能得到所需的结果。

5 个答案:

答案 0 :(得分:3)

试试这个

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

答案 1 :(得分:1)

你需要添加另一个单引号以逃避名称中的单引号,即'Rupesh'''

示例:

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

SELECT * FROM
AppliedPolicies
WHERE PolicyDesc = @Name

答案 2 :(得分:1)

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

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

答案 3 :(得分:0)

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

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

答案 4 :(得分:0)

试试这个SQL

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