【问题标题】:Unclosed quotation mark after the character string "Catch Fry's Low Impact''字符串“Catch Fry's Low Impact”后的非闭合引号
【发布时间】:2019-02-03 08:31:16
【问题描述】:

我需要匹配字符串转义单引号。这就是我的查询的样子:

select  Distinct(a.item) 
from [dbo].[Subscribtions] a
where a.Item like 'Catch Fry''s Low Impact''

但它正在抛出错误

字符串“Catch Fry's Low Impact”后的非闭合引号。

我不能使用like pattern matching% 有多个这样的字符串。由于某些数据原因,我只能使用=

谢谢

【问题讨论】:

    标签: sql sql-server tsql


    【解决方案1】:

    查看您的查询

    select  Distinct(a.item) 
    from [dbo].[Subscribtions] a
    where a.Item like 'Catch Fry''s Low Impact''
    

    'Catch Fry''s Low Impact'' 的最后一个' 多了一个,Distinct(a.item) 也不需要括号。

    由于您在字面上寻找'Catch Fry''s Low Impact',因此

    select  Distinct a.item 
    from [dbo].[Subscribtions] a
    where a.Item like 'Catch Fry''s Low Impact';
    

    将与

    相同
    select  Distinct a.item 
    from [dbo].[Subscribtions] a
    where a.Item = 'Catch Fry''s Low Impact';
    

    所以,我认为你只是在寻找

    select  Distinct a.item 
    from [dbo].[Subscribtions] a
    where a.Item = 'Catch Fry''s Low Impact';
    

    除非您进行通配符匹配,否则使用 LIKE 运算符没有任何好处。

    【讨论】:

      猜你喜欢
      • 2021-07-12
      • 1970-01-01
      • 1970-01-01
      • 2017-12-19
      • 1970-01-01
      • 2019-02-14
      • 1970-01-01
      • 1970-01-01
      • 2014-04-22
      相关资源
      最近更新 更多